Page 1 of 1
Something weird with sessions happening
Posted: Tue Jul 13, 2004 6:31 pm
by pinehead18
I have a user based site using session. It is acting really weird when i first log in using sessions it takes me to mypage which is a page that you get when first logged in. Then when i click on another page that requires sessions it goes back to the login page and asks me to login again so i do. Then everythign works fine from that point on until i close my browser or log out and have to log back in.
Any ideas?
thank you
Anthony
Posted: Tue Jul 13, 2004 6:54 pm
by Deemo
sessions expire when the browser closes. if you would like to continue being logged in, use cookies
Posted: Tue Jul 13, 2004 7:05 pm
by pinehead18
Like i said above, i never close the browser. It logs me in, i click on a link that requires sessions and it takes me back to the login page. So i login one more time and then i'm good to go UNTIL the session expires which is normal.
Any input?
Posted: Tue Jul 13, 2004 7:09 pm
by feyd
it doesn't require cookies... where in the page is the session started? i.e. Is it started in a frame/iframe? Is it started on each frame/iframe?
Posted: Tue Jul 13, 2004 9:42 pm
by Deemo
oh sorry, i misread

Posted: Wed Jul 14, 2004 3:29 am
by Wayne
is there any difference in the way you are calling the pages. ie. is one called by IP address and the other by a dns url or are the pages mypage and the other pages mentioned on different urls?
Posted: Wed Jul 14, 2004 5:56 am
by Sat
Usually such errors appears in case of overwrite session variables. I think you have to check all your operations with your session variables which controls auth on your site...
Posted: Wed Jul 14, 2004 10:49 am
by pinehead18
Even though, after i login once more time, everything works fine after that? But its the first page i view after the first time i login everytime. It is anypage that requires sessions. But after i log back in, any of the pages that did it before, work fine.
Posted: Wed Jul 14, 2004 5:53 pm
by pinehead18
My sessions are called first thing on the page.
sat: what do you mean an over right? See after i login for the 2nd time, i can view any page and never have a problem again. But i always have to login twice. I know for 100% fact it sets the session even the second time. But get this. It only requires you to login again if your this is the first time your the browser that is open has been on the page. else it always works even after the user logs out.
Any other ideas? Here is my login code..
And here is the code that is called on the top of the first page it views (mypage)
Code: Select all
<?php
$con = mysql_connect("localhost","pinehead","") or die(mysql_error());
$db = mysql_select_db("pinehead",$con) or die(mysql_error());
$lastlogon = date("l, M, d");
$pass = md5($pass);
$sql = "SELECT * FROM users where user='$uname' and pass='$pass'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
if ($row["user"] == $uname && $row["pass"] == $pass) {
$lastlogon = date("l, M, d");
session_start();
$_SESSION['name'] = $_POST['uname'];
if(isset($_SESSION['name'])) {
$sqll = "UPDATE users SET last_logon='$lastlogon' WHERE user='".$_POST['uname']."'";
if(mysql_query($sqll)) {
header("location: http://www.kc.com/mypage");
}
else {
echo "Couldn't update user<br />".$sqll."<br />".mysql_error()."";
}
}
else {
echo "Couldn't Set User Session";
}
}
else {
$output = "<center><font face=arial size=-1 color=red>Username/Password do not match <a
href=loginbox.php>Click here to login again</a></font></center>";
include('html.inc.php');
start_header($output);
}
?>
and this is the code called at the top of mypage
Code: Select all
<?php
require('html.inc.php');
user_check();
and user check is located in html.inc.php and is as follows
function user_check() {
if(!isset($_SESSION['name'])) { header("Location: http://www..com/loginbox.php"); exit; }
?>
Thank you again
Posted: Wed Jul 14, 2004 9:08 pm
by John Cartwright
Code: Select all
<?php
require('html.inc.php');
user_check();
and user check is located in html.inc.php and is as follows
function user_check() {
if(!isset($_SESSION['name'])) { header("Location: http://www..com/loginbox.php"); exit; }
?>
should be
Code: Select all
<?php
//and user check is located in html.inc.php and is as follows
function user_check() {
if(!isset($_SESSION['name'])) { header("Location: http://www..com/loginbox.php"); exit; }
require('html.inc.php');
user_check();
?>
I BELIEVE because you have not declare what user_check() is until after it is called. Not too sure on this. But this would explain why it only works on the 2nd refresh
Posted: Thu Jul 15, 2004 7:29 am
by pinehead18
Thank you for you rhelp but unfortunantly it does not work . It has always been called after it was delcared.
Any other ideas?
thank you
anthony
Posted: Thu Jul 15, 2004 10:44 am
by feyd
I don't see a session_start() in that second page's code pinehead18..
Posted: Thu Jul 15, 2004 11:14 am
by d3ad1ysp0rk
phenom, read closer, the function is IN the included file

Posted: Thu Jul 15, 2004 4:01 pm
by pinehead18
the session_start() happens in the include file since it is pulled on EVERY page of the site