Jump to content

page not redirecting using header


SUNIL16

Recommended Posts

Hi Friends

 

Below is my code for login authentication

if ($_POST['Submit']=='Login')
{
$username = mysql_real_escape_string($_POST['uname']);
$md5pass = md5($_POST['password']);
$sql = "SELECT usersid,username FROM users WHERE 
            username = '$username' AND 
            password = '$md5pass' AND user_activated='1'"; 

$result = mysql_query($sql) or die (mysql_error()); 
$num = mysql_num_rows($result);

    if ( $num != 0 ) { 

        // A matching row was found - the user is authenticated. 
       session_start(); 
   list($user_id,$usernamel) = mysql_fetch_row($result);
	// this sets variables in the session 
	$_SESSION['user']= $username;  


	if (isset($_GET['ret']) && !empty($_GET['ret']))
	{
	header("Location: $_GET[ret]");
	} else
	{
	header("Location: http://www.xyz.com/myaccount.php");
	}
	//echo "Logged in...";
	exit();
    } 

header("Location: login.php?msg=Invalid Login");
echo "Error:";
exit();		
}

 

I am not getting redirect to myaccount.php using header function.

 

please help..

 

any header functions are not functioning in my pages..

Link to comment
Share on other sites

I just tried:

 

<?php
if (true)
{
$username = mysql_real_escape_string($_POST['uname']);
$md5pass = md5($_POST['password']);
$sql = "SELECT usersid,username FROM users WHERE
            username = '$username' AND
            password = '$md5pass' AND user_activated='1'";
         
//$result = mysql_query($sql) or die (mysql_error());
//$num = mysql_num_rows($result);

    if ( true ) {

        // A matching row was found - the user is authenticated.
       session_start();
      list($user_id,$usernamel) = mysql_fetch_row($result);
      // this sets variables in the session
      $_SESSION['user']= $username; 
      
         
      if (isset($_GET['ret']) && !empty($_GET['ret']))
      {
      header("Location: $_GET[ret]");
      } else
      {
      header("Location: http://www.yahoo.com");
      }
      //echo "Logged in...";
      exit();
    }

header("Location: http://google.com");
echo "Error:";
exit();      
}
?>

 

and worked. I was redirected to yahoo.com, and if the second true is changed to false I will get redirected to google.com

 

is

$_POST['Submit']=='Login'

 

being set? (does it returns true?)

Link to comment
Share on other sites

Thanks for reply to both of you,

 

below is my form code

<form name="myform" action="login.php" method="post" onSubmit="return validate()">

<table class="main_txt" border="1"  width="100%">

  <tr>

    <td width="595" colspan="2" bgcolor="#BFBFBF" ><font color="#FFFFFF"><b>Login</b></font></td>

  </tr>

  <tr>

    <td width="292" bgcolor="#EBEBEB" >User Name</td>

    <td width="301" bgcolor="#EBEBEB" > <input type="text" name="uname" size="20" maxlenght="30"></td>

  </tr>

  <tr>

    <td width="292" bgcolor="#EBEBEB" >Password</td>

    <td width="301" bgcolor="#EBEBEB" > <input type="password" name="password" size="20" maxlenght="10"></td>

  </tr>

  <tr>

    <td width="595" colspan="2" bgcolor="#BFBFBF" height="1">                                  

      <input type="Submit" name="Submit" value="Login"> (<a href="forgotpass.html">Forgot password</a>)</td>

  </tr>

</table>

</form>

 

I used caps only.

 

and $_POST['Submit']=='Login' is setting but still i am not getting.

 

Is there anything like header should be used at the top of all other code?

Link to comment
Share on other sites

i given redirection to www.yahoo.com but still its not working.

 

here i am posting the entire code once again. Please look into it and let me know where i went wrong..

 

<h1 class="h1" align="left"> Login</h1>

<?php

require "config.php";

 

if ($_POST['Submit']=='Login')

{

$username = mysql_real_escape_string($_POST['uname']);

$md5pass = md5($_POST['password']);

$sql = "SELECT usersid,username FROM users WHERE

            username = '$username' AND

            password = '$md5pass' AND user_activated='1'";

 

$result = mysql_query($sql) or die (mysql_error());

$num = mysql_num_rows($result);

 

    if ( $num != 0 ) {

 

        // A matching row was found - the user is authenticated.

      session_start();

  list($user_id,$usernamel) = mysql_fetch_row($result);

// this sets variables in the session

$_SESSION['user']= $username; 

 

 

 

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

{

header("Location: $_GET[ret]");

} else

{

header("Location: http://www.yahoo.com");

}

//echo "Logged in...";

exit();

    }

 

header("Location: login.php?msg=Invalid Login");

echo "Error:";

exit();

}

 

?>

 

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

<table class="main_txt" border="1"  width="100%">

  <tr>

    <td width="595" colspan="2" bgcolor="#BFBFBF" ><font color="#FFFFFF"><b>Login</b></font></td>

  </tr>

  <tr>

    <td width="292" bgcolor="#EBEBEB" >User Name</td>

    <td width="301" bgcolor="#EBEBEB" > <input type="text" name="uname" size="20" maxlenght="30"></td>

  </tr>

  <tr>

    <td width="292" bgcolor="#EBEBEB" >Password</td>

    <td width="301" bgcolor="#EBEBEB" > <input type="password" name="password" size="20" maxlenght="10"></td>

  </tr>

  <tr>

    <td width="595" colspan="2" bgcolor="#BFBFBF" height="1"> 

      <input type="Submit" name="Submit" value="Login"> (<a href="forgot.php">Forgot password</a>)</td>

  </tr>

</table>

</form>

 

i am not getting header msg any thing with header function in all my pages.

Link to comment
Share on other sites

A) You never posted that complete code before,

B) You have HTML content being output on line one of that file that prevents the headers from working,

C) Wherever you put the lines of code for full php error reporting was not in that file because you would have gotten errors telling you where the HTML content was being output.

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.