Jump to content

Help Creating A Login System


topflight

Recommended Posts

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:8) 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:8) 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

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.

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.