1

my login page doesnt redirect me to the next webpage even if i inputted correct data on username and password.

when i check the config.inc and made it to config.php

it doesnt displays anything on the webpage.

any suggestions

CONFIG.INC

 $con=mysqli_connect("localhost","root@localhost","","test");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

LOGINPROC PAGE

<?php

// Inialize session
session_start();

// Include database connection settings
include('config.inc');

// Retrieve username and password from database according to user's input
$login = mysql_query("SELECT * FROM users WHERE (username = '" . mysql_real_escape_string($_POST['username']) . "') and (password = '" . mysql_real_escape_string(md5($_POST['password'])) . "')");

// Check username and password match
if (mysql_num_rows($login) == 1) {
// Set username session variable
$_SESSION['username'] = $_POST['username'];
// Jump to secured page
header('Location: securedpage.php');
}
else {
// Jump to login page
header('Location: index.php');
}

?>

securedpage.php

<?php

// Inialize session
session_start();

// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username'])) {
header('Location: index.php');
}

?>
<html>

<head>
<title>Secured Page</title>
</head>

<body>

<p>This is secured page with session: <b><?php echo $_SESSION['username']; ?></b>
<br>You can put your restricted information here.</p>
<p><a href="logout.php">Logout</a></p>

</body>

</html>
4
  • Is anything being output by config.inc? Commented May 21, 2013 at 1:30
  • @FreshPrinceOfSO no output on config.inc Commented May 21, 2013 at 1:49
  • kindly check my new post code sir thanks Commented May 21, 2013 at 2:18
  • In your config file, you are using MySQLi functions to connect to the database; however, in your login page, you are using the old mysql_ functions, not sure if that will cause a problem, but it is best to stay consistent. Commented May 21, 2013 at 2:55

3 Answers 3

0

Make sure nothing is output before the header function, including any white space in your PHP file and any included PHP files

Sign up to request clarification or add additional context in comments.

Comments

0

Also check the files for any BOM unicode, this is usually an option in the editor applications , I would suggest you to comment the header function and use a echo to check if the if or the else are being done

1 Comment

what is the header function ser? im sorry i just started yesterday in php
0

does your form in the same login page or a separate page? if it's in the same login page, try using an if ($_POST['submit']) then run your code. if it's in a separate page make sure in your form action you have the path for the login page.

1 Comment

kindly check my new post code sir thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.