Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Localhost session_id problem

Status
Not open for further replies.

mancroft

Programmer
Oct 26, 2002
267
GB
Localhost session_id problem

Hello

I am running PHP off localhost on my home computer and putting a shopping cart together.

The code below sets the session_id OK but when I change from page1.php to page2.php, the session_id number is changed when it should stay the same.

Is there a setting for session cookies in a PHP config file on the local machine that needs changing?

Thanks.

Code:
function gettheid(){if (isset($_COOKIE["theshoppingcartdemoid"])){return $_COOKIE["theshoppingcartdemoid"];}else{session_start();
setcookie("theshoppingcartdemoid", session_id(), time() + 3600 * 24 *30, "/", "",0);return session_id();}}

 
<facetious>
You don't have much use for code indentation, do you?
</facetious>

Out of curiosity, why are you setting the session cookie yourself? Why not just invoke session_start() and then manipulate $_SESSION?





Want the best answers? Ask the best questions! TANSTAAFL!
 
Hello sleipnir214

I am doing it this way because I originally got the code for a basic shopping cart out of a book and this was how it was done.

I have had this working before on a remote server but can't get it to work on my local machine and thought there might be a setting in php config or whatever that hadn't been set properly.

Ref your question: Is there a better way of doing it?
 
SOLVED

"you should use session_start(); at the beginning of every page, not just in a conditional.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top