papaface Posted January 16, 2007 Share Posted January 16, 2007 Hello,My script works on everyones server so far except one person.The sessions arent being set.Is there anything I can add to the below code to set the session if $_SESSION["username"] and $_SESSION["password"] arent set?[code]<?phperror_reporting(E_ALL);ini_set('display_errors', '1');require("../includes/checker.php");require ('../includes/connect.php') ;require ('../includes/checklogin.php') ;if ($logged_in == 1) { echo "You are already logged in ".$_SESSION["username"]; echo "<br>" . '<a href="submissions.php">' . "Click here to view pending Link Exchanges" . "</a>"; echo "<br>" . '<a href="approved.php">' . "Click here to view approved(active) Link Exchanges" . "</a>"; echo "<br>" . '<a href="logout.php">' . "Click here to logout!" . "</a>"; exit; }if (isset($_POST["submit"])) { if(!$_POST["username"] | !$_POST["password"]) { die("You did not enter the required fields"); } $check = mysql_query("select username,password from users where username='".$_POST["username"]."'") or die ("error" . mysql_error()); list($username,$password) = mysql_fetch_array($check); $_POST["username"] = stripslashes($_POST["username"]); //strip the slashes if (!$_POST["username"] == $username) { echo "The username you entered does not exist"; exit; } $_POST["password"] = stripslashes($_POST["password"]); //strip the slashes $encpass = md5($_POST["password"]); if ($encpass != $password) { die("Sorry you entered the wrong password"); } else { $_SESSION["username"] = $_POST["username"]; $_SESSION["password"] = $_POST["password"]; echo "You are now logged in " . $_SESSION["username"]; echo "<br>" . '<a href="submissions.php">' . "Click here to view pending Link Exchanges" . "</a>"; echo "<br>" . '<a href="approved.php">' . "Click here to view approved(active) Link Exchanges" . "</a>"; echo "<br>" . '<a href="logout.php">' . "Click here to logout!" . "</a>"; mysql_close($con); } }else { echo '<table width="100%" height="100%" cellpadding="2" cellspacing="2" border="0"><tr><td align="center" valign="middle"> <form action="'. $_SERVER['PHP_SELF'] .'" method="post" enctype="application/x-www-form-urlencoded"> Username: <input name="username" type="text" /> Password: <input name="password" type="password" /> <input name="submit" type="submit" value="Submit" /> </form></td></tr></table>'; }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34475-session-not-being-set/ Share on other sites More sharing options...
Philip Posted January 16, 2007 Share Posted January 16, 2007 You need session_start(); at the top of your page. Quote Link to comment https://forums.phpfreaks.com/topic/34475-session-not-being-set/#findComment-162395 Share on other sites More sharing options...
papaface Posted January 16, 2007 Author Share Posted January 16, 2007 I should have included the checklogin.php file:[code]<?phprequire ('connect.php') ;session_start();if (!isset($_SESSION["username"]) || !isset($_SESSION["password"])) { $logged_in = 0; return; }else { $pass = mysql_query("select password from users where username='".$_SESSION['username']."'",$con); list($password) = mysql_fetch_array($pass); if(mysql_num_rows($pass) != 1) { $logged_in = 0; unset($_SESSION['username']); unset($_SESSION['password']); } if ($password = $_SESSION["password"]) { $logged_in = 1; } else { $logged_in = 0; unset($_SESSION['username']); unset($_SESSION['password']); } }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34475-session-not-being-set/#findComment-162397 Share on other sites More sharing options...
papaface Posted January 16, 2007 Author Share Posted January 16, 2007 Please help :( Quote Link to comment https://forums.phpfreaks.com/topic/34475-session-not-being-set/#findComment-162413 Share on other sites More sharing options...
papaface Posted January 17, 2007 Author Share Posted January 17, 2007 Bump again Quote Link to comment https://forums.phpfreaks.com/topic/34475-session-not-being-set/#findComment-162776 Share on other sites More sharing options...
papaface Posted January 17, 2007 Author Share Posted January 17, 2007 There must be someone that can help me :( Quote Link to comment https://forums.phpfreaks.com/topic/34475-session-not-being-set/#findComment-162839 Share on other sites More sharing options...
trq Posted January 17, 2007 Share Posted January 17, 2007 You need session_start() at the top of all pages using sessions. Your question was answered 3 bumps ago! Quote Link to comment https://forums.phpfreaks.com/topic/34475-session-not-being-set/#findComment-162853 Share on other sites More sharing options...
papaface Posted January 17, 2007 Author Share Posted January 17, 2007 If you look checklogin.php is included on every page so session_start() is included on every page... Quote Link to comment https://forums.phpfreaks.com/topic/34475-session-not-being-set/#findComment-162855 Share on other sites More sharing options...
Philip Posted January 17, 2007 Share Posted January 17, 2007 You could always try session_register(); before hand. Sometimes it helps.[quote]My script works on everyones server so far except one person.[/quote]What is that one person running? What PHP settings? Quote Link to comment https://forums.phpfreaks.com/topic/34475-session-not-being-set/#findComment-162910 Share on other sites More sharing options...
ted_chou12 Posted January 17, 2007 Share Posted January 17, 2007 oh, if you have another php page script, and it has session_start(); at the top, is requiring that php script at the top of the page okay?Ted Quote Link to comment https://forums.phpfreaks.com/topic/34475-session-not-being-set/#findComment-162912 Share on other sites More sharing options...
papaface Posted January 17, 2007 Author Share Posted January 17, 2007 Argh I must have changed something in one of these files because now it isnt working for me either on my localmachine, when it was working before. Quote Link to comment https://forums.phpfreaks.com/topic/34475-session-not-being-set/#findComment-162936 Share on other sites More sharing options...
papaface Posted January 17, 2007 Author Share Posted January 17, 2007 Ah I have found the error:was:[code] $_SESSION["username"] = $_POST["username"]; $_SESSION["password"] = $_POST["password"][/code]should have been:[code] $_SESSION["username"] = $_POST["username"]; $_SESSION["password"] = $encpass;[/code]Thanks for all of your help guys! Quote Link to comment https://forums.phpfreaks.com/topic/34475-session-not-being-set/#findComment-162941 Share on other sites More sharing options...
trq Posted January 17, 2007 Share Posted January 17, 2007 [quote]You could always try session_register(); before hand. Sometimes it helps.[/quote]session_register() has long been depricated. Quote Link to comment https://forums.phpfreaks.com/topic/34475-session-not-being-set/#findComment-162966 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.