Click here to Skip to main content
15,888,340 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
I am using this code in other website working there but in my current website everything working but only page not redirecting after login.

here is my code
PHP
<?php

if(isset($_POST["Login"]))
{
if ($_POST["username"]=="" || $_POST["password"]=="")
{
 echo "<script>alert('You need to provide a username and password!')</script>";
}
else
{
$user_name=$_POST["username"];
$password=$_POST["password"];
$q = "SELECT name,status FROM info WHERE email_id='$user_name' AND pass='$password'";
$data=mysql_query($q,$con) or die("Error in Query: " . mysql_error());
$num=mysql_fetch_array($data);
if(!$num)
{
echo "<script>alert('Sorry! E-Mail Id and Password donot match!')</script>";
}
else
{
$uname=$num['name'];
$ustatus=$num['status'];
if($ustatus=='lock')
{
echo "<script>alert('You Are Currently block Contact for more details!')</script>";
}
else
{

$_SESSION["user_name"]= $uname;
$_SESSION["user_email"]=$user_name;
header('Location:http://www.mysite.com/');
}
}

}
}
else
{}

value coming in session an if i put any alert msg after session value its working but only page not redirecting to location.
If any of you has any suggestion for this code pls reply.

here is the code that working..
PHP
<?php
if(isset($_POST["Submit"]))

{
$user_name=$_POST["username"];
$password=$_POST["password"];
if (!$_POST["username"] || !$_POST["password"])
        {
        die("You need to provide a username and password.");
        }

    // Create query

  $q = "SELECT * FROM info WHERE email_id='".$_POST["username"]."' AND pass='".$_POST["password"]."'";

  // Run query
  $r = mysql_query($q);
  if ( $obj = @mysql_fetch_object($r) )
   {
	$status=$obj->status;
		if($status=='lock')
         {
          echo "<script>alert('You Are Currently block Contact for more details!')</script>";
         }
         else
          {
        $_SESSION["user_name"]= $obj->name;
       $_SESSION["user_email"]=$obj->email_id;
            header("Location:http://www.mysite.com/index.php");
          }
   }
  else
        {

       // Login not successful

      echo "<script>alert('Sorry, could not log you in. Wrong login informatio.')</script>";

	          }


}

else{

}


Thanks
Posted
Updated 15-Apr-13 2:00am
v3
Comments
Prasad Khandekar 15-Apr-13 7:24am    
For redirect to work no HTML should get sent to the client. In your scenario it's likely that one of the echo is getting executed prior to redirect and hence redirect is not working. Here is a good article (http://www.cyberciti.biz/faq/php-redirect/)
[no name] 15-Apr-13 7:28am    
thanks
I read the same but couldnot able to understand what should not come.
Thanks let check this..
[no name] 15-Apr-13 7:59am    
Code change but still not working..

if(isset($_POST["Login"]))
{
if ($_POST["username"] !="" || $_POST["password"] !="")
{
$user_name=$_POST["username"];
$password=$_POST["password"];
$q = "SELECT name,status FROM info WHERE email_id='$user_name' AND pass='$password'";
$data=mysql_query($q,$con) or die("Error in Query: " . mysql_error());
$num=mysql_fetch_array($data);
if($num)
{
$uname=$num['name'];
$ustatus=$num['status'];
$uemail=$num['email_id'];
if($ustatus=='unlock')
{
$_SESSION["user_name"]= $uname;
$_SESSION["user_email"]=$uemail;
header('Location:http://www.mysite.com/index.php');
}
else
{
echo "<script>alert('You Are Currently block Contact for more details!')</script>";
}

}
else
{
echo "<script>alert('Sorry! E-Mail Id and Password donot match!')</script>";
}
}
else
{
echo "<script>alert('You need to provide a username and password!')</script>";
}
}
else
{}

1 solution

Hi,
I use this for solve this problem.

JavaScript
$url = 'http://www.makemyindianshaadi.com/index.php';
echo "<script language=\"javascript\">location.href=\"$url\";</script>";

But taking time to redirect.
Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900