topflight Posted October 15, 2008 Share Posted October 15, 2008 I am trying to create a login system and for some reason I am having one minor problem when the user login. I have 3 Pages, One is the actual login form,The Second one loginc.php which checks to see if the information is ok and, the last one is only for users. With that saying when I type in the wrong information the script does what is suppose to do. However when I type in the write information I am receiving this error right here. Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\loginc.php: in C:\xampp\htdocs\loginc.php on line 25 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\loginc.php: in C:\xampp\htdocs\loginc.php on line 27 Here is my code: login.php <table align="center" cellpadding="1"> <form action=loginc.php method=post> <tr> <td width="45"><b>Login</b></td> <td width="144"><input type="text" name="login" value="<?php echo $_POST['login'];?>" /></td> </tr> <tr> <td><b>Password</b></td> <td><input type="password" name="pwd" value="<?php echo $_POST['pwd'];?>" /></td> </tr> <td><input name="submit" type="submit" value="Login!"/></td> <td><input name="reset" type="reset"/></td> </form> loginc.php(checks to make sure everything is ok!) <?php include 'db.php'; ?> <?php $login = $_POST['login']; $pwd = $_POST['pwd']; // STop MySQL Injections $myusername = stripslashes($login); $mypassword = stripslashes($pwd); $myusername = mysql_real_escape_string($login); $mypassword = mysql_real_escape_string($pwd); $result = mysql_query("SELECT * FROM pilots WHERE login='$login' and pwd='$pwd'"); $count = mysql_num_rows($result); if($count==1){ session_register("$login"); session_register("$pwd"); header("location:pilotc.php"); } else { echo "Incorrect Pilot ID and/or Password"; } ?> Userpart Only(Only for users who are logged in and have an account.) <?php if(isset($_SESSION['login'])){ echo'test'; } else { echo'You are not Loged In'; } ?> F.Y.I I have tried putting the session stuff at the top of the script on the loginc.php, but then it doesn't operate properly. Thanks in Advanced. Link to comment https://forums.phpfreaks.com/topic/128540-help-creating-a-login-system/ Share on other sites More sharing options...
GKWelding Posted October 15, 2008 Share Posted October 15, 2008 When you added the session_register to the top of the page, you say it didn't work, instead, add session_start(); to the top of the page leaving the rest of the code as is... Link to comment https://forums.phpfreaks.com/topic/128540-help-creating-a-login-system/#findComment-666148 Share on other sites More sharing options...
revraz Posted October 15, 2008 Share Posted October 15, 2008 At the top of loginc.php, the first line of code put session_start(); Then change if($count==1){ session_register("$login"); session_register("$pwd"); header("location:pilotc.php"); to if($count==1){ $_SESSION['login'] = $login; $_SESSION['pwd'] = $pwd; header("location:pilotc.php"); Change pilotc.php the same way. Link to comment https://forums.phpfreaks.com/topic/128540-help-creating-a-login-system/#findComment-666152 Share on other sites More sharing options...
topflight Posted October 15, 2008 Author Share Posted October 15, 2008 Thanks it work but I am trying to add a part of code on loginc.php to look like this <?php if($count==1){ $_SESSION['login'] = $login; $_SESSION['pwd'] = $pwd; header("location:pilotc.php"); } else ( echo 'Incorrect Pilot ID and/or Password'; } ?> And I am now recceving an Parse error: syntax error, unexpected T_ECHO in C:\xampp\htdocs\loginc.php on line 25 Wired huh? All I am doing is just doing an stupid else statement (lol) Link to comment https://forums.phpfreaks.com/topic/128540-help-creating-a-login-system/#findComment-666174 Share on other sites More sharing options...
GKWelding Posted October 15, 2008 Share Posted October 15, 2008 Exactly what it says, you have a syntax error replace } else ( with } else { Link to comment https://forums.phpfreaks.com/topic/128540-help-creating-a-login-system/#findComment-666176 Share on other sites More sharing options...
topflight Posted October 15, 2008 Author Share Posted October 15, 2008 oo ok thanks. Link to comment https://forums.phpfreaks.com/topic/128540-help-creating-a-login-system/#findComment-666177 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.