Hello, I have a few problems that I need help with and any help recieved would be greatly appreciated. Here we go My script works on everyones server so far except one person. The sessions arent being set on this persons server. Is there anything I can add to the below code to set the session if $_SESSION["username"] and $_SESSION["password"] arent set? login.php: <?php error_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>'; } ?> PHP: checklogin.php: <?php require ('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']); } } ?> PHP: What can be causing this issue on this persons server, and how can I make sure it doesnt happen?
They are enabled. Session Support enabled Registered save handlers files user Directive Local Value Master Value session.auto_start Off Off session.bug_compat_42 On On session.bug_compat_warn On On session.cache_expire 180 180 session.cache_limiter nocache nocache session.cookie_domain no value no value session.cookie_lifetime 0 0 session.cookie_path / / session.cookie_secure Off Off session.entropy_file no value no value session.entropy_length 0 0 session.gc_divisor 100 100 session.gc_maxlifetime 1440 1440 session.gc_probability 1 1 session.name PHPSESSID PHPSESSID session.referer_check no value no value session.save_handler files files session.save_path /tmp /tmp session.serialize_handler php php session.use_cookies On On session.use_only_cookies Off Off session.use_trans_sid Off Off
As far as checking if they're already set, PHP has an isset function you can use. How to you mean they're not being set? You're inputting a value and you can't echo that value out? Check what version of PHP you're using on that particular server, the session function syntax has changed a bit over the various versions. Cheers, -kthnx PS: I tried to link you to the manual entry for isset but being a new member I'm not allowed to I'm sure you can google it.
I understand isset. He is running php 4.4.4. I have tried all the old ways of setting a session but none of them work. The reason I know the sessions are not being set is because he logs into my script. When he clicks on a link he gets a message stating that he is not logged in.
I see. Looks like you've tried everything server side; does the script work when you run it? Maybe a browser compatibility issue at his end?
Yes the script runs perfectly for me and everyone else that has run it. It isnt a clients side issue as I tried the script on his server and it didnt work for me either.
Is it possible that there's a MySQL connection issue? I know that you've set error reporting to all, but maybe your connection code is using the @ symbol? Also, you have a bug in checklogin.php: if ($password = $_SESSION["password"]) should be: if ($password == $_SESSION["password"]) I mean, I know it really doesn't matter (the session is server side etc.) but it's still a bug
Thanks for pointing out the bug. It cant be a mysql issue as it wouldnt let them login if it was. It does let them login, but then when they click a link to go to another page, they get logged out....
Ah I have found the error: was: $_SESSION["username"] = $_POST["username"]; $_SESSION["password"] = $_POST["password"] Code (markup): should have been: $_SESSION["username"] = $_POST["username"]; $_SESSION["password"] = $encpass; Code (markup): Thanks for all of your help guys!