Page 1 of 1
PHP problems with sessions - help
Posted: 2007-02-28 08:50am
by His Divine Shadow
It's really quite a simple problem, but I'm an utter PHP newbie, anyway I got this code:
Code: Select all
<?php
session_start();
$_SESSION['specificYear'] = $_POST['specificYear'];
$_SESSION['specificMake'] = $_POST['specificMake'];
$_SESSION['specificModel'] = $_POST['specificModel'];
header("Location: /shop/catalog/index.php?cPath=1");
?>
This is located in a page of its and its job is to store a few values as sessions and go back to where it came from, then these values can be recalled elsewhere on the site. Their purpose is to be used as filtering criteria in an SQL code.
The problem is that the values aren't saved, nomatter what I try I can't save the values. How do I properly store values and recall them elsewhere?
Posted: 2007-02-28 11:49am
by His Divine Shadow
You where right that session_start(); wasn't there in the other file, stupid misstake but anyway it broke the code. I am modifying an existing opensource code. Anyway I switched to cookies:
Code: Select all
<?php
setcookie("specificYear", $_POST['specificYear'], time()+604800); /* Expires in a week */
setcookie("specificMake", $_POST['specificMake'], time()+604800); /* Expires in a week */
setcookie("specificModel", $_POST['specificModel'], time()+604800); /* Expires in a week */
//print $_COOKIE['specificYear'];
header("Location: /shop/catalog/index.php?cPath=1");
?>
Now the print cookie code works when viewing it in the page that sets it, but after the redirect I cannot call it up with the same code in the other page.
Posted: 2007-02-28 07:07pm
by Spyder
Destructionator XIII wrote:(Also a potential pitfall: make sure there are no new lines before or after the <?php ?> in both files - it messes up session handling too, as I recently learned the hard way.)
When I started with PHP I spent days on that one.
Posted: 2007-03-01 02:08am
by His Divine Shadow
That above sounds like you are saying that there can bo no other code like say HTML in a document if you want to use sessions.
Posted: 2007-03-01 10:09am
by His Divine Shadow
I just didn't get sessions to work quite simply. And putting session_start(); at the beginning of the page the code was supposed to return to after entering the session values simply made the page blank, I am not sure if OSCommerce (I am modifying this software to filter products based on vehicle properties) has sessions on or if it breaks because of it, at any rate it seems like a giant task to check out all the code and files considering I started coding in php this monday.