clanstyles Posted June 21, 2007 Share Posted June 21, 2007 I have a script for login. It works fine. The people can login ect.. I save the session information during login. It even prints out the correct info. But when they go to another page like main.php it loses all the info and goes you are not loged in. Why? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/56570-solved-session-help/ Share on other sites More sharing options...
trq Posted June 21, 2007 Share Posted June 21, 2007 Does main.php have a call to session_start() at the top? Quote Link to comment https://forums.phpfreaks.com/topic/56570-solved-session-help/#findComment-279399 Share on other sites More sharing options...
clanstyles Posted June 21, 2007 Author Share Posted June 21, 2007 yep. I have a config.php file and it starts the session and is included in every file. Quote Link to comment https://forums.phpfreaks.com/topic/56570-solved-session-help/#findComment-279403 Share on other sites More sharing options...
trq Posted June 21, 2007 Share Posted June 21, 2007 Are cookies enabled in the browser? Otherwise, you'll need to post some code. Quote Link to comment https://forums.phpfreaks.com/topic/56570-solved-session-help/#findComment-279407 Share on other sites More sharing options...
clanstyles Posted June 21, 2007 Author Share Posted June 21, 2007 Here ill post it all but config info. login.php <?php include("header.php"); if (!$_SESSION['entered']) { $errror = false; if(isset($_POST['submit'])) { $result = mysql_query("select * from accounts"); while($res = mysql_fetch_array($result)) { if(strtolower($_POST['username']) == strtolower($res['username']) && md5($_POST['password']) == $res['password']) { echo $username; echo $password; $_SESSION['uname'] = $_POST['username']; $_SESSION['pass'] = $_POST['password']; $_SESSION['entered'] = true; echo "done"; echo "<br />"; break; } else { $_SESSION['entered'] = false; echo "bad login"; } } if($_SESSION['entered']) header("Location: main.php"); } else { echo "<center>"; ?> <form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>" id="submit"> Username: <input type="text" name="username" size="16" /><br /> Password: <input type="password" name="password" size="16" /><br /> <div align="center"> <p><input type="submit" value="Login" id="submit" name="submit" /></p> </div> </form> </center> <?php } } else { echo "<a href=\"" . session_destroy() . "\">Logout</a>"; echo "<br /><a href=\"main.php?" . SID . "\">main</a>"; } include("footer.php"); ?> header.php <?php include("config.php"); ?> <html> <header> <title> Technicolor Panel </title> </header> <body> <?php session_start(); ?> config.php <?php /* Defines for Datase Connection */ $hostname = "xxxxx"; $username = "xxxxx"; $password = "xxxxx"; $database = "xxxxx"; /* Connection String Start */ mysql_connect($hostname, $username, $password) or die(mysql_error()); /* Select Database */ mysql_select_db($database); ?> main.php <?php include("header.php"); if (!$_SESSION['entered']) { echo "haha doesn't work."; } else { echo "Works nice..."; echo "<br /><a href=\"login.php?" . SID . "\">main</a>"; } include("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/56570-solved-session-help/#findComment-279409 Share on other sites More sharing options...
clanstyles Posted June 21, 2007 Author Share Posted June 21, 2007 Bump.. fast posting here man Anyway. Waiting for answer. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/56570-solved-session-help/#findComment-279438 Share on other sites More sharing options...
ryeman98 Posted June 21, 2007 Share Posted June 21, 2007 I can't help but you should put that code in the code tags. That way it's easier to read. Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/56570-solved-session-help/#findComment-279441 Share on other sites More sharing options...
clanstyles Posted June 23, 2007 Author Share Posted June 23, 2007 Plz help man. Quote Link to comment https://forums.phpfreaks.com/topic/56570-solved-session-help/#findComment-280779 Share on other sites More sharing options...
wildteen88 Posted June 23, 2007 Share Posted June 23, 2007 In header.php you are calling session_start() when you have outputted HTML. You cannot call session_start() when any form of output has been made. I recommend you to add session_start() as the first line in login.php and main.php. Remove session_start from header.php. You don't need it in header.php as you are including this file. Quote Link to comment https://forums.phpfreaks.com/topic/56570-solved-session-help/#findComment-280807 Share on other sites More sharing options...
clanstyles Posted June 23, 2007 Author Share Posted June 23, 2007 ahh okay ill do that thank you very much ill try it and get back to you. Quote Link to comment https://forums.phpfreaks.com/topic/56570-solved-session-help/#findComment-280974 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.