Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

I am finding difficult to redirect the page

Links for php scripts

Moderators: macek, egami, gesf

I am finding difficult to redirect the page

Postby nanda » Thu Feb 21, 2013 9:56 pm

here is the code;

This is login.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content= "text/html; charset=utf-8"/>
<title>Creating a simple PHP and MYSQL based login system</title>
<link rel="stylesheet" type="text/css" href="login.css"/>
</head>
<body>
<form id="login-form" method="post" action="login.inc.php">
<fieldset>
<legend>Login </legend>
<p> Please enter the username and password to access the administrator's panel</p>
<label for="username">
<input type="text" name="username" id="username"/>Username:
</label>
<label for="password">
<input type="password" name="password" id="password"/>Password:
</label>
<label for="submit">
<input type="submit" name="submit" id="submit" value="login"/>
</label>
</fieldset>
</form>
</body>
</html>

As soon as the user logged in,it has to redirect to index.php........ But it is redirecting to login.inc.php
My login.inc.php

<?php
require_once('config.inc.php');
require_once('functions.inc.php');
session_start();

if(isset($_SESSION['logged_in'])== true)//Check if user is already logged in
{
header('Location:index.php'); //If user is logged in, redirect to main page
exit();
}
else
{
if((!isset($_POST['username'])) || (!isset($_POST['password'])) || (!ctype_alnum($_POST['username'])))
{
header('Location:login.php');
exit();
}

$mysql=@new mysql(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
if(mysql_connect_errno())
{
printf("Unable to connect to database : %s", mysql_connect_errno());
exit();
}
$username= $mysql->real_escape_string($_POST['username']);
$password= $mysql->real_escape_string($_POST['password']);

$sql= "SELECT * FROM users WHERE username= '".$username ."' AND password = '".md5($password)."'";
$result= $mysql->$query($sql);
if(is_object($result) && $result->num_rows==1)
{
$_SESSION['logged_in']= true;
header('Location: index.php');
exit();
}
else
{
header('Location :login.php');
exit();
}
}
?>
nanda
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu Feb 21, 2013 9:29 pm

Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.