Controling sessions

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
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Controling sessions

Post by mzfp2 »

Hi

Ive just switched to using sessions for my login system, however I find that (and my users) that while navigating between pages, or different windows, the session is lost and a re-login is required.

I was wondering if it is possible to start a session for a fixed period of time?

http://www.alljammin.com -Free funky dating and flirting
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

you are using

Code: Select all

session_start();
on every page right?
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Post by mzfp2 »

Yeah I am, every page includes a file called my_session.php which has session_start() in it
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

This thread deals exactly with your problem:

http://www.devnetwork.net/forums/viewtopic.php?p=53693
Magosoft
Forum Newbie
Posts: 3
Joined: Mon Feb 23, 2004 2:54 pm

Post by Magosoft »

Ok, every I have done everything in the thread, but.
I'm developing a page with Apache 1.3.X and php-4.3.4,
under Windows 2000 professional.

In my php.ini file I had set the session_path="C:\php\sessions"
when I start the session with:

<?php
session_start();
$_SESSION['myvar]='Some string';
echo '<a href="test.php">Test</a>';
?>

This creates a file with the name:
sess_56#######.....etc.
When I edit it is says:
myvar|s:11:"Some string"
However, when I hit the Test link on my page
the value does not exists in the new page, and
it creates me a new session file in the session folder.

The code for the test.php file is:
<?php
session_start();
echo $_SESSION['myvar'];
?>

Any help will be appreciated.

MAGO
cyberhawk
Forum Newbie
Posts: 11
Joined: Tue Mar 02, 2004 7:49 pm

Maybe this can help you?

Post by cyberhawk »

I had the same problem, check your php.ini and locate this:

session.use_trans_sid = 0

and change the 0 to 1:

session.use_trans_sid = 1

Then reboot your puter.

And then your script will work, promise.

And 4 some code, have a look at my little test.

First page

Code: Select all

<?php 
session_start(); 

$un = "anders"; 

$_SESSION['uname']=$un; 
$_SESSION['ualias']='olle'; 
echo '<pre>'; 
print_r($_SESSION); 
echo '</pre>'; 
?> 

<p><a href="test4.php">Page 2</a></p>

Second page

Code: Select all

<?php 
session_start(); 

echo '<pre>'; 
print_r($_SESSION); 
echo '</pre>'; 

echo $_SESSION['uname']; 
echo $_SESSION['ualias']; 

?>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Then reboot your puter.
Seems a bit over the top when all you need to do is restart apache to reread the php.ini :o
cyberhawk
Forum Newbie
Posts: 11
Joined: Tue Mar 02, 2004 7:49 pm

Post by cyberhawk »

:oops:
Post Reply