Jump to content

header()-function not redirecting


nosmas

Recommended Posts

:)

hello friends

 

I was working on a login form and I used header() function for working, but it ain't redirecting.It is just showing an empty(white) page.

            _____________________________________________

                            here is the php code

          _______________________________________________

 

<?php

//login.php

include('includes/db.php');

include('includes/session.php');

$user_id=$_POST['user_id'];

$password=md5($_POST['password']);//crypt the password b/c the pwd in db is crypted

 

$query1="SELECT *FROM user WHERE user_id='$user_id' AND user_password='$password'";

$result1=mysql_query($query1) or die(mysql_error());

 

if(mysql_num_rows($result1)>0){//check if the user exists in the user table

setUserSession($user_id,$password);

header("Location:user.php?SID");

exit(0);

}else{

    $query2="SELECT *FROM admin WHERE user_id='$user_id' AND password='$password'";

    $result2=mysql_query($query2) or die(mysql_error());

    die(mysql_num_rows($result2));

 

    if(mysql_num_rows($result2)>0){//check if the user exists in the admin table

    setAdminSession($user_id,$password);

    header("Location:admin.php?SID");

    exit(0);

}else{

    $msg="wrong username or password";

    header("Location:login1.php?msg=$msg");

    exit(0);

 

        }

 

}

 

?>

        __________________________________________________

                                here is the login form

        ___________________________________________________

 

 

<?

if(isset($_GET['msg']) && !empty($_GET['msg'])){

echo "<font color=\"red\" >$msg</fornt>";

}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

 

<html>

<head>

<title>Untitled</title>

</head>

<body>

<form action="login.php" method="post">

<pre>

<fieldset>

user ID<input type="text" name="user_id" maxlength="10" /><br />

Password<input type="password" name="password" maxlength="12" /><br />

<input type="submit" value="login" />

</fieldset>

</pre>

</form>

</body>

</html>

 

Link to comment
Share on other sites

You can only call the header() function if you have not previously output ANYTHING.

 

I.e. this will NOT work:

echo 'hi';
header("Location: index.php");

 

Make sure you have these lines at the top of your script to catch any errors:

 

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>

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.