Using session_start()

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
srbarker
Forum Newbie
Posts: 3
Joined: Wed Nov 20, 2002 5:45 pm
Location: Cinn, Ohio

Using session_start()

Post by srbarker »

I'm trying to use session_start to store a few variables that are required by several pages on my website. However, it seems like if I access the same page twice it resets the PHPSESSIONID initializes the variables.

If before the session_start I set the session_id to session_id("1234") it works fine.

Any ideas?
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

can you paste the top part of you code in so we can look?
srbarker
Forum Newbie
Posts: 3
Joined: Wed Nov 20, 2002 5:45 pm
Location: Cinn, Ohio

session_start()

Post by srbarker »

JPlush76 wrote:can you paste the top part of you code in so we can look?

at the top of get_coaches_user_password.php

<?php

/* start a session */

session_id("1234");
session_start();
session_register('theuser');
session_register('thepassword');

?>

at the top of validate_user_password.php


<?php

session_id("1234");
session_start();

?>

it does not work if I remove the session_id("1234")

Thanks, Steve
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

Code: Select all

&lt;?php
session_start();

$_SESSION&#1111;'theuser'] = 'jplush76';
$_SESSION&#1111;'thepassword'] = 'pass';


echo $_SESSION&#1111;'theuser'];
?&gt;
see if that works, just in case.. session_start() has to be at the VERY top of your script, even before any html or anything
srbarker
Forum Newbie
Posts: 3
Joined: Wed Nov 20, 2002 5:45 pm
Location: Cinn, Ohio

More session_start()

Post by srbarker »

Hmmm...maybe I don't understand sessions...I thought it would maintain the same session_id across multiple accesses of the same page as long as it was called from the same client / browser?

What I have noticed is if I load the same page twice with session_start() I get a new session_id....if I go from one page to the next and call session_start() at the top of each page it works fine.

A setting in my php.ini ???
Post Reply