captaintyson Posted January 18, 2010 Share Posted January 18, 2010 I've been having so much trouble with this login. It's saying its logged in but its not showing up... login success: <?php session_start(); if(!session_is_registered($PID) AND !session_is_registered($pwd)){ header("location:index.php?m=worked"); } ?> Part where its not showing the Member Center on index.php?m=worked <?php if(!isset($_SESSION['PID']) AND !isset($_SESSION['pwd'])) { ?><div id="loginbox"> <span style="font-size:14px;">Pilot Login</span><br><br> <form name="form1" method="post" action="includes/checklogin.php"> PID: <label> <input type="text" name="PID" id="PID" size="5" maxlength="4"> </label> <br>PIN:<?php echo $_SESSION['PID']; ?> <label> <input type="text" name="pwd" id="pwd" maxlength="30"> </label> <br> <label> <input type="submit" name="submit" id="submit" value="Login"> </label> </form> <br> <div align="center">Forgot Password | Join Here</div> </div><?php } else{ ?><li> <h2>Member Center</h2> <ul> <li><a href="#">Aliquam libero</a></li> <li><a href="#">Consectetuer adipiscing elit</a></li> <li><a href="#">Metus aliquam pellentesque</a></li> <li><a href="#">Suspendisse iaculis mauris</a></li> <li><a href="#">Proin gravida orci porttitor</a></li> <li><a href="#">Aliquam libero</a></li> </ul> </li> <?php } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted January 18, 2010 Share Posted January 18, 2010 session_is_registered is deprecated. So this.... <?php session_start(); if(!session_is_registered($PID) AND !session_is_registered($pwd)){ header("location:index.php?m=worked"); } ?> should be.... <?php session_start(); if(!isset($_SESSION['PID']) AND !isset($_SESSION['pwd'])){ header("location:index.php?m=worked"); } ?> And your other snippet needs a call to session_start. Quote Link to comment Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Author Share Posted January 18, 2010 Unfortunatly that didn't work. I did add session start though. Thanks for the help so far. :\ Quote Link to comment Share on other sites More sharing options...
trq Posted January 18, 2010 Share Posted January 18, 2010 Where are you actually setting these $_SESSION variables? Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 18, 2010 Share Posted January 18, 2010 I think you are a little confused aswell.. In your second snippet you have if (!isset($_SESSION['PID'])) but then you are calling it in the code block knowing that it is not set. Quote Link to comment Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Author Share Posted January 18, 2010 Actually the top of the page has this. Really sorry, I left this out <?php $page = $_GET['page']; include_once('connect.php'); session_start(); if(!isset($_SESSION['PID']) AND !isset($_SESSION['pwd'])) {} else { $PID = $_SESSION['PID']; $pwd = $_SESSION['pwd']; Quote Link to comment Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Author Share Posted January 18, 2010 Also if your looking to test it out: www.icelandva.com user:1001 pwd:4895 Quote Link to comment Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Author Share Posted January 18, 2010 And here's check login, starting to think it's a problem with this: <?php $host="asdfsdf"; // Host name $username="asdfsadfdsfasdf"; // Mysql username $password="asdf"; // Mysql password $db_name="asdf"; // Database name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from signup form $PID = $_POST['PID']; $pwd = $_POST['pwd']; $sql="SELECT * FROM Roster WHERE PID='$PID' and pwd='$pwd'"; $result=mysql_query($sql) or die(mysql_error()); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count > 0){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("PID"); session_register("pwd"); header("location:login_success.php"); echo 'Login Worked'; } else { mysql_error(); header("location:index.php?page=crew");; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Loading</title> </head> <body> </body> </html> Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 18, 2010 Share Posted January 18, 2010 You arent calling session_start() on that last page you posted..You need to call it at the top of your script. Also replace session_register("PID"); session_register("pwd"); with $_SESSION['PID'] = $PID; $_SESSION['pwd'] = $pwd; Quote Link to comment Share on other sites More sharing options...
oni-kun Posted January 18, 2010 Share Posted January 18, 2010 Yes, as mentioned session_register is a very old and deprecated method of assigning variables to the session. It should always be in the format, $_SESSION['key'] = 'value'; Quote Link to comment Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Author Share Posted January 18, 2010 So that means I need to make my login success and home page <?php session_start(); if(!session_is_registered($_SESSION['PID']) AND !session_is_registered($_SESSION['pwd'])){ header("location:index.php?m=worked"); } ?> to this <?php session_start(); if(!session_is_registered($_SESSION[$PID]) AND !session_is_registered($_SESSION[$pwd])){ header("location:index.php?m=worked"); } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted January 18, 2010 Share Posted January 18, 2010 So that means I need to make my login success and home page <?php session_start(); if(!session_is_registered($_SESSION['PID']) AND !session_is_registered($_SESSION['pwd'])){ header("location:index.php?m=worked"); } ?> to this <?php session_start(); if(!session_is_registered($_SESSION[$PID]) AND !session_is_registered($_SESSION[$pwd])){ header("location:index.php?m=worked"); } ?> No. <?php session_start(); if(!isset($_SESSION['PID']) AND !isset($_SESSION['pwd'])){ header("location:index.php?m=worked"); } ?> Quote Link to comment Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Author Share Posted January 18, 2010 Thanks so far for your help guys. It means allot when you've been up for 5 hours strait working on the same problem. Still not working, but let me get each page up to make sure I didn't miss anything. Panel.php:displays the login and when logged in the members area <?php session_start(); if(!isset($_SESSION['PID']) AND !isset($_SESSION['pwd'])) { ?><div id="loginbox"> <span style="font-size:14px;">Pilot Login</span><br><br> <form name="form1" method="post" action="checklogin.php"> PID: <label> <input type="text" name="PID" id="PID" size="5" maxlength="4"> </label> <br>Password:<?php echo $_SESSION['PID']; ?> <label> <input type="password" name="password" id="password" maxlength="30"> </label> <br> <label> <input type="submit" name="submit" id="submit" value="Login"> </label> </form> <br> <div align="center">Forgot Password | Join Here</div> </div><?php } else{ ?><li> <h2>Pilot Center</h2> <ul> <li><a href="#">Aliquam libero</a></li> <li><a href="#">Consectetuer adipiscing elit</a></li> <li><a href="#">Metus aliquam pellentesque</a></li> <li><a href="#">Suspendisse iaculis mauris</a></li> <li><a href="#">Proin gravida orci porttitor</a></li> <li><a href="#">Aliquam libero</a></li> </ul> </li> <?php } ?> Check login: <?php $host="asdfasdf.asdf.com"; // Host name $username="adsf"; // Mysql username $password="asdfadsf"; // Mysql password $db_name="asdf"; // Database name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from signup form $PID = $_POST['PID']; $pwd = $_POST['password']; $sql="SELECT * FROM `Roster` WHERE PID=$PID and pwd=$pwd"; $result=mysql_query($sql) or die(mysql_error()); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count > 0){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION['PID'] = $PID; $_SESSION['pwd'] = $pwd; header("location:login_success.php"); echo 'Login Worked'; } else { mysql_error(); header("location:index.php?page=crew");; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Loading</title> </head> <body> </body> </html> Login success: <?php session_start(); if(!isset($_SESSION['PID']) AND !isset($_SESSION['pwd'])){ header("location:index.php?m=worked"); } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted January 18, 2010 Share Posted January 18, 2010 Still not working So, what happens? Quote Link to comment Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Author Share Posted January 18, 2010 Still not working So, what happens? It just returns back to index.php?m=worked which is strange.. I tired having it echo $_SESSION['PID] but to no avail. Quote Link to comment Share on other sites More sharing options...
trq Posted January 18, 2010 Share Posted January 18, 2010 checklogin doesn't appear to have a call to session_start(). Quote Link to comment Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Author Share Posted January 18, 2010 checklogin doesn't appear to have a call to session_start(). We're getting somewhere! Alright now it's giving the mysql error that the login doesnt work. But the credentials match up. Quote Link to comment Share on other sites More sharing options...
trq Posted January 18, 2010 Share Posted January 18, 2010 Your query would be failing for sure. Try this.... <?php $host="asdfasdf.asdf.com"; // Host name $username="adsf"; // Mysql username $password="asdfadsf"; // Mysql password $db_name="asdf"; // Database name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from signup form $PID = mysql_real_escape_string($_POST['PID']); $pwd = mysql_real_escape_string($_POST['password']); $sql = "SELECT * FROM `Roster` WHERE PID='$PID' and pwd = '$pwd'"; if ($result=mysql_query($sql)) { if (mysql_num_rows($result)) { $_SESSION['PID'] = $PID; $_SESSION['pwd'] = $pwd; header("location:login_success.php"); exit(); } else { echo "Username / Password does not match"; } } else { trigger_error(mysql_error()); } ?> Are you sure your passwords aren't hashed? They should be. Quote Link to comment Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Author Share Posted January 18, 2010 Just checked error logs.. dont know what any of this means PHP Warning: session_start() [<a href='function.session-start'>function.session-start</a>]: open(/var/php_sessions/sess_e03e53657824366c7463fab135e7c2c9, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web164/b1644/ipg.icelandvacom/index.php on line 2 PHP Parse error: syntax error, unexpected $end in /hermes/bosweb/web164/b1644/ipg.icelandvacom/src/joincomplete.php on line 151 PHP Warning: Unknown: open(/var/php_sessions/sess_e03e53657824366c7463fab135e7c2c9, O_RDWR) failed: No such file or directory (2) in Unknown on line 0 PHP Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/php_sessions) in Unknown on line 0 Quote Link to comment Share on other sites More sharing options...
oni-kun Posted January 18, 2010 Share Posted January 18, 2010 Why isn't it saving sessions to (the default) /tmp? Are permissions set up properly in /var/php_sessions? CHMODDED to 755 should be sufficient, although i'm not sure if it is your direct problem as it should have warned you up front if the session could not be created. Add the following lines above session_start(); : ini_set('display_errors',1); error_reporting(E_ALL); And see if it reports any errors. Quote Link to comment Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Author Share Posted January 18, 2010 Warning: session_start() [function.session-start]: open(/var/php_sessions/sess_e03e53657824366c7463fab135e7c2c9, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web164/b1644/ipg.icelandvacom/index.php on line 4 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/bosweb/web164/b1644/ipg.icelandvacom/index.php:4) in /hermes/bosweb/web164/b1644/ipg.icelandvacom/index.php on line 4 Quote Link to comment Share on other sites More sharing options...
oni-kun Posted January 18, 2010 Share Posted January 18, 2010 Warning: session_start() [function.session-start]: open(/var/php_sessions/sess_e03e53657824366c7463fab135e7c2c9, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web164/b1644/ipg.icelandvacom/index.php on line 4 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/bosweb/web164/b1644/ipg.icelandvacom/index.php:4) in /hermes/bosweb/web164/b1644/ipg.icelandvacom/index.php on line 4 And there ya go. Are you ouputting anything, including whitespace (Newline/Space/HTML) before session_start() ? This will cause the session cookie to be voided, as headers are being sent after content. Quote Link to comment Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Author Share Posted January 18, 2010 I don't have any white space is the problem. Even when I take out that snippit you gave me. And It's also saying undefined index? Quote Link to comment Share on other sites More sharing options...
oni-kun Posted January 18, 2010 Share Posted January 18, 2010 I don't have any white space is the problem. Even when I take out that snippit you gave me. And It's also saying undefined index? At what lines is the undefined index? That error is usually called when in 'strict' error mode and is usually not the problem, but for some reason PHP cannot set the cookie for the session. It states headers have already been sent, which just leads you back to whitespace beforehand.. Quote Link to comment Share on other sites More sharing options...
captaintyson Posted January 18, 2010 Author Share Posted January 18, 2010 I don't have any white space is the problem. Even when I take out that snippit you gave me. And It's also saying undefined index? At what lines is the undefined index? That error is usually called when in 'strict' error mode and is usually not the problem, but for some reason PHP cannot set the cookie for the session. It states headers have already been sent, which just leads you back to whitespace beforehand.. Line 4.. which is session start. :\ Could it be the server I'm on? Quote Link to comment 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.