Session Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
southpaw17er
Forum Newbie
Posts: 8
Joined: Fri Aug 04, 2006 12:58 pm

Session Help

Post by southpaw17er »

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi all,

I've recently installed Apache 2, mysql, and PHP 5 on a Windows XP machine.  All is working well except for sessions in php.  I've tried everything I can think of and have reduced a test page to this:

PAGE 1 - test.php

Code: Select all

<?php

session_start();

$_SESSION['test'] = 'hello';

echo $_SESSION['test'];

?> 

<a href="test2.php">click me</a>
PAGE 2 - test2.php

Code: Select all

<?php

session_start();

echo $_SESSION['test'];

?>

Hello gets displayed on page 1, but not page two. Could my ini file be configured incorrectly? Thanks in advance for any help.


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Have you cleared your browser cache? Start with that and see if it helps.
southpaw17er
Forum Newbie
Posts: 8
Joined: Fri Aug 04, 2006 12:58 pm

Post by southpaw17er »

Thanks for the help, I cleared my cache, and still got nothing. I've tried restarting my browser, using both Firefox and IE, and restarting Windows, but I still get nothing.

Any Ideas?

Thanks again
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Try this...
test1.php

Code: Select all

<?php
session_start();
echo session_id();
$_SESSION['test'] = 'hello';
echo $_SESSION['test'];
echo '<pre>' . print_r($_SESSION) . '</pre>';
echo '<br /><br /><a href="test2.php">Click me to go to page 2</a>';
?>
test2.php

Code: Select all

<?php
session_start();
if (isset($_SESSION['test']))
{
    echo $_SESSION['test'];
}
else
{
    echo '<pre>' . print_r($_SESSION) . '</pre>';
}
echo '<br /><br /><a href="test1.php">Click me to go to back to page 1</a>';
?>
southpaw17er
Forum Newbie
Posts: 8
Joined: Fri Aug 04, 2006 12:58 pm

Post by southpaw17er »

Everah:

I tried that code and received this output for test.php,


fo2abdb7vpan29dv79c2o8ja73helloArray ( [test] => hello )

1



And for test2.php, only

Array ( )

1


So it still appears that it's not working.

Thanks again for your help.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Have you searched these boards for 'session not working'? I vaguely recall something similar to this being posted by another poster a few months ago. I forget what the resolution was, but I think he got it resolved.

Is this happening on a hosted server or a local server? Do you have access to the sessions data folder that PHP uses for storing session data?
southpaw17er
Forum Newbie
Posts: 8
Joined: Fri Aug 04, 2006 12:58 pm

Post by southpaw17er »

I searched through a few dozen posts similar to mine, but the only problem that seemed logically to fit with my situation is when a firewall was restricting use of sessions. I tried it with my firewall off, but it still does not work.

Also, this is happening on a local windows xp machine. There is a sessiondata folder in c:/php, but my php.ini file is set to put session data in c:/temp. However, both of those are empty, so it appears not to be recording anything.

Thanks
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

What are the permissions on the sessiondata folders (both in /php and in /temp)?
southpaw17er
Forum Newbie
Posts: 8
Joined: Fri Aug 04, 2006 12:58 pm

Post by southpaw17er »

Both folders had read-only checked under attributes in properties. I unchecked both and still no session variables would pass. Also, when I go back and look at properties, a square box is in the read-only box, whether I left it checked or unchecked.

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Is the server running under a different user? It's normal for the server to run under a different user than the one you're logged in as. Make sure that user has permission to write in those directories.
southpaw17er
Forum Newbie
Posts: 8
Joined: Fri Aug 04, 2006 12:58 pm

Post by southpaw17er »

I only have one user account on this computer, the administrator account. So I assume the server must be running on this same account.

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There are a lot more accounts than those you can see in the User Accounts panel. For instance, there's the SYSTEM account, the SERVICE account, and so forth.
southpaw17er
Forum Newbie
Posts: 8
Joined: Fri Aug 04, 2006 12:58 pm

Post by southpaw17er »

So how would I determine which of these accounts my server is running off of?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Does

Code: Select all

<?php phpinfo(); ?>
say something about USERPROFILE? And is it <whatever>\LocalService ?
southpaw17er
Forum Newbie
Posts: 8
Joined: Fri Aug 04, 2006 12:58 pm

Post by southpaw17er »

volka:

Yes, under USERPROFILE is C:\Documents and Settings\LocalService
Is this how it should be?

Thanks
Post Reply