home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 1700
Discussions: 188,401, Posts: 2,243,608, Members: 232,631
Old April 8th, 2005, 08:22 PM   Digg it!   #1 (permalink)
Ultimate Member
 
FatalException's Avatar
 
Join Date: Jun 2004
Location: Indianapolis, Indiana
Posts: 1,386
Working with Sessions in PHP

I'm trying to design a site that uses sessions in PHP, but I'm having some trouble. I want to make it so that if a user clicks a link on page1.php of my website, it takes them to page2.php of the site and displays a variable that I stored in the session on page 1. However, if they go DIRECTLY to page2.php, I want it to show nothing or produce an error. Now, it does this OK as long as the person has never been to the site before - but if they go to page1.php, click the link (which takes them to page2.php), it displays the information as it should... but then if they return to the site later and go DIRECTLY to page2.php without clicking the link on page1.php, it STILL has the information stored and displays it. Refreshing the page doesn't help.

It's like once a session is made in PHP, it never gets vaporized, even if the browser is closed and reopened. I'd like it so that after, say, 5 minutes the session expired and all variables opened in that session automatically closed, but I can't for the life of me figure out how to do this. I tried playing with the session_cache_expire() function, as described on php.net, but it doesn't do what I want. Ideas?

page1.php code:
PHP Code:
<?php
session_cache_expire
(1);
session_start();
$_SESSION['EXISTS']=1;
$_SESSION['data']="This is the text stored in the data variable.";
echo 
"<br ><a href=\"page2.php\">Click Here</a>";
$sid=session_id();
echo 
"<br >$sid";
?>
page2.php code:
PHP Code:
<?php
session_cache_expire
(1);  //should make data vanish after 1 minute!
session_start();
$expire_val=session_cache_expire();
echo 
"Expiration $expire_val<br>";
$out=$_SESSION['data'];
echo 
"Information: $out<br>";
?>
__________________
Logic shall prevail.

FatalException is offline   Reply With Quote
Old April 9th, 2005, 12:03 AM     #2 (permalink)
Ultimate Member
 
FatalException's Avatar
 
Join Date: Jun 2004
Location: Indianapolis, Indiana
Posts: 1,386
Sorry to bump so soon after the original post, but any help would be appreciated. Thanks!

FatalException is offline   Reply With Quote
Old April 9th, 2005, 12:06 AM     #3 (permalink)
Real gangstas sip on Yacc
 
jkrohn's Avatar
 
Join Date: Oct 2001
Location: Suckas-ville
Posts: 4,549
Send a message via ICQ to jkrohn Send a message via AIM to jkrohn Send a message via Yahoo to jkrohn
How about adding a referrer check? Depending on your need for security this would do the job.

Jkrohn

jkrohn is offline   Reply With Quote
Old April 9th, 2005, 12:08 AM     #4 (permalink)
Real gangstas sip on Yacc
 
jkrohn's Avatar
 
Join Date: Oct 2001
Location: Suckas-ville
Posts: 4,549
Send a message via ICQ to jkrohn Send a message via AIM to jkrohn Send a message via Yahoo to jkrohn
Also take a look at the session variables in php.ini. Might be something useful in there.
Specificly gc_maxlifetime.
jkrohn is offline   Reply With Quote
Old April 9th, 2005, 12:09 AM     #5 (permalink)
Ultimate Member
 
FatalException's Avatar
 
Join Date: Jun 2004
Location: Indianapolis, Indiana
Posts: 1,386
I guess the underlying intention is to get the session to expire after about 10 minutes. Currently, it takes over 1 hour to do it. I just don't know where that default setting is. Referrer checks won't work since we're working with personal information that is somewhat sensitive.

I don't have access to php.ini on my server, either. So I was hoping to implant a special variable into the session somewhere that would cause an earlier expiration.

Last edited by FatalException : April 9th, 2005 at 12:13 AM.
FatalException is offline   Reply With Quote
Old April 9th, 2005, 12:10 AM     #6 (permalink)
Ultimate Member
 
Join Date: Jan 2003
Location: MA / NH
Posts: 1,497
Send a message via AIM to Blazer06
What if you were to use session cookies instead? Or is that not an option?

If you just want them to be able to view for X minutes, I would just make and check for a cookie… that way they could close the browser, thirty seconds later open it, go to your site again with no problems, yet in X minutes, they would have to re-log in / whatever.


-Blaze
Blazer06 is offline   Reply With Quote
Old April 9th, 2005, 12:11 AM     #7 (permalink)
Real gangstas sip on Yacc
 
jkrohn's Avatar
 
Join Date: Oct 2001
Location: Suckas-ville
Posts: 4,549
Send a message via ICQ to jkrohn Send a message via AIM to jkrohn Send a message via Yahoo to jkrohn
Try changing the cache option in php.ini.

Jkrohn
jkrohn is offline   Reply With Quote
Old April 9th, 2005, 12:14 AM     #8 (permalink)
Ultimate Member
 
FatalException's Avatar
 
Join Date: Jun 2004
Location: Indianapolis, Indiana
Posts: 1,386
Quote:
Originally Posted by Blazer06
What if you were to use session cookies instead? Or is that not an option?

If you just want them to be able to view for X minutes, I would just make and check for a cookie… that way they could close the browser, thirty seconds later open it, go to your site again with no problems, yet in X minutes, they would have to re-log in / whatever.
PHP does use session cookies by default, and that is what I'm using in this situation. How do I poison the cookie, though, to kill itself after a certain amount of time? They are generated automatically on the client-side by the "start_session()" function.
FatalException is offline   Reply With Quote
Old April 9th, 2005, 12:31 AM     #9 (permalink)
Ultimate Member
 
FatalException's Avatar
 
Join Date: Jun 2004
Location: Indianapolis, Indiana
Posts: 1,386
Quote:
Originally Posted by jkrohn
Try changing the cache option in php.ini.
Unfortunately I don't have access to that file on the server. I was hoping for a variable that I could create along with the session to specify how long it should last before it times out due to inactivity. Ideas?
FatalException is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Emailing... not working...?? fishsponge Webmastering and Programming 0 September 13th, 2004 07:16 AM
PHP code not working cracked Webmastering and Programming 3 February 26th, 2004 11:15 PM
NFS3:HP networked sessions dunbar General Gaming Discussion 2 February 19th, 2003 11:51 AM
PHP Not working for .html file vass0922 Webmastering and Programming 7 November 10th, 2002 04:16 AM
adding sessions to cdr tomm Multimedia and Audio 4 February 5th, 2002 02:57 AM

Most Active Discussions
Is It Just Me? (2906)
3-days in and no threads about Gaza (161)
Unarmed man on his stomach shot by .. (6)
New Build ( Finally ) (7)
CPU wont boot (7)
Building a gaming computer advice (5)
I think I just killed my computer w.. (24)
RCA 52Inch HDTV wont turn on (5)
Folderchat Weekday thread (444)
Recent Discussions
Laptop proccesor to desktop mob.. (2)
Please help! multiple problems! (4)
RCA 52Inch HDTV wont turn on (5)
New Build ( Finally ) (7)
Common Spyware Solutions (97)
How do you move a hard-drive to.. (4)
What is the best external enclo.. (0)
Partition Magic 7.0 (Unallocate.. (17)
For cheap price and good qualit.. (1)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 04:19 AM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28