Jump to content

[SOLVED] Login not working


Ads

Recommended Posts

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\wamp\www\Athina\loginck.php:13) in C:\wamp\www\Athina\loginck.php on line 14

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\Athina\loginck.php:13) in C:\wamp\www\Athina\loginck.php on line 14

 

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\Athina\loginck.php:13) in C:\wamp\www\Athina\loginck.php on line 26

 

loginck.php

<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
    <link href="style1.css" rel="stylesheet" type="text/css">
<title></title>
</head>
<body>
<?php
  session_start();
  include "include/db.php";
  if (isset($_POST['Submit'])) {
    $email = mysql_real_escape_string($_POST['email']);
    $password = mysql_real_escape_string($_POST['password']);
    $sql = "SELECT username FROM players WHERE email='$email'";
    if ($result = mysql_query($sql)) {
      if (mysql_num_rows($result)) {
        $row = mysql_fetch_assoc($result);
        $_SESSION['username'] = $row['username'];
        header("Location: main.php");
      }
    }
  }
  ?>

</body>

</html>

Link to comment
Share on other sites

  • Replies 64
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Read the comment

<?php session_start(); // this session start must be very top of the page 
// no extra whitespace allowed too... 

include "include/db.php";
// 
  if (isset($_POST['Submit'])) {
    $email = mysql_real_escape_string($_POST['email']);
    $password = mysql_real_escape_string($_POST['password']);
    $sql = "SELECT username FROM players WHERE email='$email'";
    if ($result = mysql_query($sql)) {
      if (mysql_num_rows($result)) {
        $row = mysql_fetch_assoc($result);
        $_SESSION['username'] = $row['username'];
        header("Location: main.php");
      }
    }
  }
?>

<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
    <link href="style1.css" rel="stylesheet" type="text/css">
<title></title>
</head>
<body>

</body>

</html>

Link to comment
Share on other sites

Remove all of the HTML.. it does nothing and is not needed.

 

<?php
session_start();
include "include/db.php";
if (isset($_POST['Submit'])) {
    $email = mysql_real_escape_string($_POST['email']);
    $password = mysql_real_escape_string($_POST['password']);
    $sql = "SELECT username FROM players WHERE email='$email'";
    if ($result = mysql_query($sql)) {
        if (mysql_num_rows($result)) {
          $row = mysql_fetch_assoc($result);
          $_SESSION['username'] = $row['username'];
          header("Location: main.php");
        }
    }
}
?>

 

PhREEEk

Link to comment
Share on other sites

Keep this code and try

 

<?php session_start(); // this session start must be very top of the page 
include "include/db.php";
// 
  if($_SERVER['REQUEST_METHOD'] == 'POST')
   {
    $email = mysql_real_escape_string($_POST['email']);
    $password = mysql_real_escape_string($_POST['password']);

    $sql = "SELECT username FROM players WHERE email='$email' AND password='$password'";
// here you echo the SQL
// if it is found it will show something like this 
// Select username From players Where email='john@abcd.com' AND password='abcdefgh';

$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);

     if ($num_rows > 0) 
 {
       $_SESSION['username'] = $row['username'];
       header("Location: main.php");
     }
 else
 {
 // if it is not found then it will show this error...
  echo "Username not found in Database";
 }
    
}

?>

Link to comment
Share on other sites

here is all my Code for all three pages.

 

login.php

<!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=iso-8859-1" />
<title>Login</title>
<link href="style1.css" rel="stylesheet" type="text/css" />
</head>

<body>
<form method="post" action="loginck.php" target="_parent">
<p align="center">
<span class="style2">Enter Email:</span> <br>
  <input type="text" name="email" id="email">
  <br>
  <span class="style2">Enter Passowrd:</span><br>
  <input type="password" name="password">
  <br>
  <input name="Submit" type="submit" class="top" value="Submit">
    </p>
<p align="center"> </p>
<p align="center">
  </div>
      <strong>Messages:</strong>
</p>
</p>
    <div align="center">Working on</div>
    
    
</body>
</html>

 

loginck.php

<?php session_start(); // this session start must be very top of the page 
include "include/db.php";
// 
  if($_SERVER['REQUEST_METHOD'] == 'POST')
   {
    $email = mysql_real_escape_string($_POST['email']);
    $password = mysql_real_escape_string($_POST['password']);

    $sql = "SELECT username FROM players WHERE email='$email' AND password='$password'";
// here you echo the SQL
// if it is found it will show something like this 
// Select username From players Where email='john@abcd.com' AND password='abcdefgh';
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);

     if ($num_rows > 0) 
 {
       $_SESSION['username'] = $row['username'];
       header("Location: main.php");
     }
 else
 {
 // if it is not found then it will show this error...
  echo "Username not found in Database";
 }
    
}
?>

 

main.php

 

<?php session_start(); ?>
<?php 
include "include/db.php";
?>

<!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>Game xD</title>
  <link href="style1.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php

  if (!isset($_SESSION['username'])) {
    echo "<p>you are not allowed to acces this page</p>";
  } else {
    echo "{$_SESSION['username']}";
  }

?>
</body>
</html>

</body>
</html>

Link to comment
Share on other sites

Now Just make two files login.php and main.php

 

login.php

please note, I checked this code with my database it is working, some variables name may be mismatched then your code, please check first

<?php 
session_start(); // this session start must be very top of the page 
include ("include/db.php");

// I checked with my database and table, it is perfectly working for me 
//$link = mysql_connect("localhost", "root", '');
//mysql_select_db("********", $link);
// you can comment these lines 

// you don't have to use two pages for login, you can do it in one page 
// if user press the submit button
  if($_SERVER['REQUEST_METHOD'] == 'POST')
   {
   
    $email = mysql_real_escape_string($_REQUEST['email']);
    $password = mysql_real_escape_string($_REQUEST['password']);
// validate the form 

	if (empty($email))
	$msg = "Please enter an email<br>";
	if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $_REQUEST['email'])) 
	$msg .= "Email not Valid<br>";
	if (empty($password))
	$msg .= "Please enter password<br>";

	// if there are no errors you can proceed and check in the DB 

	if (empty($msg))
	{
	//"SELECT username FROM players WHERE email='$email' AND password='$password'";
	$sql = "SELECT username FROM players WHERE email='$email'";
	$result=mysql_query($sql) or die("Your have an error because:<br />" . mysql_error());
	// here you echo the SQL
	// if it is found it will show something like this 
	// Select username From players Where email='john@abcd.com' AND password='abcdefgh';
	$result = mysql_query($sql);


		if(mysql_num_rows($result)!=0)
		 {
		   $array=mysql_fetch_array($result);
		   $usrname = $array['username'];
		   //$_SESSION['username'] = $usrname;
		  	$success = TRUE;
		  		if ($success)
				{
				header("Location: main.php");
				$_SESSION['username'] = $usrname;
				}
		  			   
		 }
		 else
		 {
		 // if it is not found then it will show this error...
		  echo "Username not found in Database";
		 }
    	


	}

}

?>
<!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=iso-8859-1" />
<title>Login</title>
<link href="style1.css" rel="stylesheet" type="text/css" />
</head>

<body>
<form method="post">
<p align="center">
<span class="style2">Enter Email:</span> <br>
  <input type="text" name="email">
  <br>
  <span class="style2">Enter Passowrd:</span><br>
  <input type="password" name="password">
  <br>
  <input name="Submit" type="submit" class="top" value="Submit">
    </p>
<p align="center"><?php if(!empty($msg)) {echo $msg;}?></p>
<p align="center">
  </div>
      <strong>Messages:</strong>
</p>
</p>
    <div align="center">Working on</div>
    
</body>
</html>

 

and

main.php

<?php session_start();

if (isset($_SESSION['username']))
{
echo ("Welcome ".$_SESSION['username']);
}
else
{
echo "I hate you!!!";
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.