session_start help

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
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

session_start help

Post by Crashin »

Howdy all! Can someone enlighten me about handling sessions with session_start and the other session functions? I have used session_start on all the pages I need session control for, and I have set the session variable in my login code. Likewise, I check the variable using session_is_registered("variable") to produce output if returned true. My problem is this...if a user quits out of their browser without logging-out via my site's logout page, which uses session_unregister("variable") and session_destroy, they are unable to use the site successfully upon next login without first going through the logout page. They can log in, but when any other page is attempted the session isn't read by the page and they are required to login.

Additionally, and this is a sidenote to my main problem above, is there a quick method to controlling the session when the user exits the page at all (i.e. the BACK button)? I'm getting better with PHP, however I've read all the session stuff at PHP.net and still haven't been able to resolve the problem. Thanks!
Matt
Forum Newbie
Posts: 2
Joined: Mon May 06, 2002 5:12 pm

Post by Matt »

User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post by Crashin »

That covered what I've already done, but thanks for the post! :)
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

I hope this helps

Post by gotDNS »

I dont know if this will help, but here is how I use sessin varibles:

Code: Select all

<?php
session_start();

mysql_connect("localhost:3306", "troop21") && mysql_select_db("troop21")
or $failed = "Could not connect to database.";

$loginform = "&nbsp;&nbsp;&nbsp;User: <input type="text" size="13" name="pn" maxlength="16" />
Pass: <input type="password" size="13" name="pw" maxlength="12" />&nbsp;
<input type="submit" value="Login" />";

$result = mysql_query("select * from users where patrolnum="$pn"");

$row = mysql_fetch_assoc($result);

if($row&#1111;"password"]==md5($pw) && !session_is_registered("loggedin"))
&#123;
	$loggedin=$pn;
	session_register("loggedin");
&#125;
else if(session_is_registered("loggedin"))
&#123;
	$logerror="<img src="smile.gif" height="13" width="13" /> <b class="MESSAGE">You're already logged in.</b>";
&#125;
else if($row&#1111;"password"]!=md5($pw))
&#123;
	$pwerror="<b class="RED">ERROR:</b> <b class="MESSAGE">Username or password did not match!</b>";
&#125; ?>
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post by Crashin »

Thanks for the info! :D
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

NP

Post by gotDNS »

No problem. Copy and Paste my code.

http://brin.ath.cx
Post Reply