d22552000 Posted October 27, 2007 Share Posted October 27, 2007 LOGIN CODE: include('inc/conf.php'); //session started in here if (isset($_GET['login'])) { $login = clean($_POST['l']); mysql_connect(localhost,'root',''); $result=mysql_query("SELECT `ID` FROM `*`.`users` WHERE user='$login' AND pass='".md5($_POST['b'])."'") or die(mysql_error()); if(!mysql_num_rows($result)>0) { html('Error','Login Invalid',true); } else { session_regenerate_id(); $member=mysql_fetch_assoc($result); $_SESSION['MID']=$member['ID']; //Write session to disc session_write_close(); header("location: index.php?LID=".rand()); exit(); } } INDEX.PHP: <?PHP include('inc/conf.php'); //session started in here if (!empty($_SESSION['MID'])) { header('location: login.php'); exit(); } html('Members Home','<div align="right"><a href="login.php?logout">Logout</a></div><br/>Welcome, '.$_SESSION['MIN'].'. Logged In!<br/><br/>Sorry, but we haven\'t made the user control panel yet ',true); ?> INC/CONF.PHP <?PHP include('../html/html.php'); include('../../log.php'); $SELF = $_SERVER['PHP_SELF']; $HOST = $_SERVER['HTTP_HOST']; $RADD = $_SERVER['REMOTE_ADDR']; $RHST = $_SERVER['REMOTE_HOST']; $RPRT = $_SERVER['REMOTE_PORT']; $REFR = $_SERVER['HTTP_REFERER']; $REQU = $_SERVER['REQUEST_TIME']; $QURY = $_SERVER['QUERY_STRING']; $CONN = $_SERVER['HTTP_CONNECTION']; $USAG = $_SERVER['HTTP_USER_AGENT']; __log($SELF,$HOST,$RADD,$RHST,$RPRT,$REFR,$REQU,$QURY,$CONN,$USAG); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // some day in the past header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); session_start(); ?> and I get redirected back to the login page whats wrong? Quote Link to comment https://forums.phpfreaks.com/topic/75039-solved-login-script-not-setting-session/ Share on other sites More sharing options...
marcus Posted October 27, 2007 Share Posted October 27, 2007 Try making session start the first line of that file. Quote Link to comment https://forums.phpfreaks.com/topic/75039-solved-login-script-not-setting-session/#findComment-379444 Share on other sites More sharing options...
cooldude832 Posted October 27, 2007 Share Posted October 27, 2007 don't do all that extra session stuff, to register a session say <?php session_start(); //At top //Some stuff to test $_SESSION['FieldName'] = $value; //Done ?> On the login page say a <?php foreach($_SESSION as $key => $value){ echo $key.": ".$value."<br />"; } ?> That above test is good for testing lots of stuff liek get, post, session. You might have a spelling issue somehwer Quote Link to comment https://forums.phpfreaks.com/topic/75039-solved-login-script-not-setting-session/#findComment-379447 Share on other sites More sharing options...
d22552000 Posted October 27, 2007 Author Share Posted October 27, 2007 it was a really stupid error in index php I was redirecting to login only if they were logged in I had: if (!empty and I should have had if (empty I figured this out becasue the index worked when I restarted the browser. Quote Link to comment https://forums.phpfreaks.com/topic/75039-solved-login-script-not-setting-session/#findComment-379448 Share on other sites More sharing options...
cooldude832 Posted October 27, 2007 Share Posted October 27, 2007 there you go Quote Link to comment https://forums.phpfreaks.com/topic/75039-solved-login-script-not-setting-session/#findComment-379450 Share on other sites More sharing options...
d22552000 Posted October 27, 2007 Author Share Posted October 27, 2007 and I was trying to figure that one out for a good half hour Quote Link to comment https://forums.phpfreaks.com/topic/75039-solved-login-script-not-setting-session/#findComment-379463 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.