Why are session variables not passing to next page

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

jramaro
Forum Commoner
Posts: 58
Joined: Tue Jun 26, 2007 7:46 am

Post by jramaro »

hey Jim , somethin to keep in mind is that when you use session_start()
it will pass Sesisons to the next page, but only if on the firts page, if those were set as a sessions

example $_SESSION['widget'] ;

but when you use a FORM that the user submits it isnt making them sessions yet. because they dont exist until user submits form.

Then , your second page has to read something like this:
Pretend one of the inputs was for the user to input their name on page one.
You couldnt use $_SESSION['name'] on page 1.
Because it wont exist when that page loads, not until user submits that form .

when it goes to page two . you want to have something to converted that POST data to a session
like this :

Code: Select all

$_SESSION['name'] = $_POST['name'];
your form on page one will have to be method="post" or "get" if you want to send it that way .
But on form submits and user input data , the Session cant exist until it is 1. submitted to next page. (becomes a $_POST variable)
2. you convert it to sessions.

its a simple thing like a roller skate laying on a stair , important to realize that the $_POST and $_SESSION tactics
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

@jramaro: I'm fairly certain that he was already doing everything that you stated in your post.
jramaro
Forum Commoner
Posts: 58
Joined: Tue Jun 26, 2007 7:46 am

Post by jramaro »

My bad..
its just that his post was SO frigign HUGE 8O
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Before we start diagnosing the problem (and making statements to the mental state of the poster) can we be sure that sessions are working?

@ Original Poster: Have you ran the session testing scripts yet? What are the results?
jramaro
Forum Commoner
Posts: 58
Joined: Tue Jun 26, 2007 7:46 am

Post by jramaro »

why?! ...

did somebody call me crazy!? ...

(looks around wildly)
jimdavidson
Forum Newbie
Posts: 13
Joined: Thu Jul 26, 2007 10:10 am

Post by jimdavidson »

Problem solved.

For the header I had this...
header('Location: http://bobtracyinsurance.com/btracy_auto_quotes_2.php');

What I should have had was this...
header('Location: http://www.bobtracyinsurance.com/btracy ... otes_2.php');

Three little w's made the difference, session variables now work.

I'll get better, one thing going for me is that I keep trying.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

That means that there is something screwey with your session cookie domain. If the domain is akin to 'domain.com' then you should change that to '.domain.com' and it will work for any subdomain of your domain, including 'www'.
jimdavidson
Forum Newbie
Posts: 13
Joined: Thu Jul 26, 2007 10:10 am

Post by jimdavidson »

Thanks, that's something else for me to learn.

Life was so much easier in the old days of DOS.
jimdavidson
Forum Newbie
Posts: 13
Joined: Thu Jul 26, 2007 10:10 am

Post by jimdavidson »

session cookie domain?

I assume that I find that by running phpinfo()?

I did and the results from the server say...

session.cookie_domain Local value = (no value) and Master value = (no value).

Is this correct or do I need to have the web host put some value in there?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

That should do for the most part, at least according to the manual. Though I know that the domain 'domain.com' may not include the domains in '.domain.com'.
Post Reply