Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 20th, 2004, 05:50 AM
Registered User
 
Join Date: Apr 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default sessions wont persist


after fixing the my original problems with sessions ( setting "session.save_path" from "/tmp" > "c:\php\sessiondata" )
i am no longer reciving any warnings!

But now my the problem is that my sessions wont persist. if i return the following code:

    session_start();

    session_register('counter');

    $counter++;
    echo("You have visited this page $counter times! Don't you have anything
    else to do, you bum?!");

    echo strip_tags(SID);

and i refresh the page. I always get :

    "You have visited this page 1 times! Don't you have anything else to do, you bum?!"

as you can see $counter is not adding to itself each time and the SID isnt doing anything.

the above code works fine when i upload it to my www host its just my local machine i am running w2k - am i missing something?

 
Old April 20th, 2004, 11:29 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

This is a problem with register_globals, its turned off by default. Don't use session_register, use the $_SESSION superglobal instead. You treat these just like regular variables.

session_start();

if (!isset($_SESSION['counter']))
{
    $_SESSION['counter'] = 0;
}

$_SESSION['foo'] = 'Hello, World!';

$_SESSION['counter']++;

Read this post on why session_register is bad:
http://p2p.wrox.com/topic.asp?TOPIC_ID=2052

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old April 22nd, 2004, 01:56 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The SID isn't doing anything because you're not actually creating a LINK with it -- you're just echoing it to the user.

That said, when you refresh the page, PHP still doesn't have a session ID, so it creates a new session every time.

If you configure PHP to use cookies to store the session ID, and to enable the transparent session ID feature, then your code will work when you refresh the page. That's because the SID is stored in a cookie on the user's machine, so their browser sends it to PHP via HTTP headers, instead of attaching it to all links and via hidden input fields in all forms...


make sense?



Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Persist DataSet in ViewState bnorg ASP.NET 2.0 Professional 1 May 22nd, 2007 07:46 AM
Client(javascript) from asp:button wont persist VictorVictor ASP.NET 2.0 Professional 35 February 27th, 2007 03:40 PM
Problem with check persist KamalRaturi ASP.NET 2.0 Professional 0 September 23rd, 2006 07:12 PM
Sessions wont disconnect boxalld Apache Tomcat 0 June 2nd, 2005 10:52 AM
Mixing classic ASP sessions with ASP.NET sessions scorpion_king General .NET 2 August 4th, 2004 08:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.