PHP Session usage

Leb_CRX

Gawd
Joined
Sep 25, 2003
Messages
567
trying to setup a page for a client

has to pass variables between several pages

using the start_session() *on every page, right below body tag* and $_SESSION variable

but running into a problem where it wont remember the session at all when the new page is called...new page is called with a get

the main page calls page2 using

page2?loc_id=#

now page 2 can display loc_id fine, and I stored loc_id in $_SESSION['loc_id'] and I can echo it fine

but when I 'get' to page 3, the value $_SESSION['loc_id'] is empty

any ideas?
 
I don't think your problem is within php.ini simply because it likely wouldn't work for the 2nd page if it was.

If you are passing the session ID between pages, check that page 3 is receiving the session ID- if it isn't there is a problem on page 2.

Also try checking that you don't remove session variables or delete the contents of loc_id by mistake at some point. (Or that the variable going into loc_id is not valid on page 2. This is another possibility)

Sessions can be quite annoying sometimes... If these don't help, maybe post more code.
 
HerrKevin said:
I don't think your problem is within php.ini simply because it likely wouldn't work for the 2nd page if it was.

If you are passing the session ID between pages, check that page 3 is receiving the session ID- if it isn't there is a problem on page 2.

Also try checking that you don't remove session variables or delete the contents of loc_id by mistake at some point. (Or that the variable going into loc_id is not valid on page 2. This is another possibility)

Sessions can be quite annoying sometimes... If these don't help, maybe post more code.
the thing is page1->2 doesn't use session ID

page 1 calling page 2 looks like:

<a href="page2?loc_id=1">link</a>

now page 2 has this code there right below body
Code:
<?php
session_start();
$_SESSION['loc_id'] = $HTTP_GET_VARS['loc_id']; 
?>

now I use this value, and it works fine, cause I can print it and it shows correct ID

now...somewhere later in the file, doing a few if statements, and thats fine

then I have my form, here's the action
Code:
<form action="page3.php?" method="get" name="form1">

then in page3 when I echo the $_SESSION['loc_id'] I get nothing
 
I wrote a simple class to handle sessions, it made life so much easier. Just a suggestion.
 
I did the print "session id is: " . session_id(); on every page to see the session ID...well

page2 session ID:
session id is: 287df2f56542bc91474aba5ae38f6c92

page3 session ID:
PHP has encountered an Access Violation at 01A87BD4session id is: c1526767ff977379fec68f5d88ab4b35

any ideas?
 
BinaryCleric said:
I wrote a simple class to handle sessions, it made life so much easier. Just a suggestion.
I honestly just need to get this done ASAP, nothing fancy as long as it works

is there an easy and fast way for me to set another variable to the location ID on the 2nd page and pass it using the 'get' action?

like inside the form?

I just need this to work :(
 
BinaryCleric said:
I wrote a simple class to handle sessions, it made life so much easier. Just a suggestion.

This is what I normally do for larger projects as well, but if it's only 3 files then I wouldn't see any reason to.

Anyway, I didn't realize no sessions were started until the 2nd page. If you are getting an access error, maybe you should check to see where PHP is saving sessions and try to save them directly to a folder of your choosing (I've done this before, I forget the variable. It's in the PHP docs).

Also worth noting is that if your server is running windows, you may need to update PHP or install a patch that deals with access problems. I only did a quick google search on this though, so I'm not sure how old this problem is.
 
thanks Herr

is there anyway I can just send the value from page2 file to page 3 using the 'get', without having to deal with sessions?

like read it, save it in a variable, and when I go to call page3, I have it somewhere in the call and have the ability to read it in page3? I dont care if it gets resent

I hope that makes sense, and is easy

if I can get a snip of code if thats possible, just to point me in the right direction, that would be great

I tried adding it to the <form action="name.php?loc_id=<?php echo $variable;?>"> but that seemed to be overwritten when the GET was actually called

thanks
 
Back
Top