Jump to content

Blank Page on redirect


Baabu

Recommended Posts

Hello every one ,

<?
include ("db.php");
if(authenticateUser($username,$upass))
{
	setcookie("cookie_passwd",$upass);
	setcookie("cookie_user",$uname);

	//echo "cookie set";
	header("Location:Http://localhost/cart/list.php");
		exit;
}

else
{
		//echo "un";
		header("Location:http://localhost/cart/index.php");
		exit();
}





?>

in the above code everything is working fine even it displays cookie set(which is for just checking) when i a put a comment on the echo statement the page just goes blank and no redirect. Can anyone help me out !!! ???

Best Regards

Baabu

Link to comment
https://forums.phpfreaks.com/topic/93466-blank-page-on-redirect/
Share on other sites

If you echo ANYTHING to the browser (even a space) before the location header, the header will fail and you aren't forwarded anywhere. This is what is happening to you.

 

You must have error reporting turned off, or you would have an error telling you about this problem.

well here are both the code

<?

$dbserver="localhost";
$dbadmin="ar";
$pass="pass";
$dbname="cart";

function authenticateUser($user,$upass)
{
	global $dbserver,$dbadmin,$pass,$dbname;
	$cxn=connectToDb($dbserver,$dbadmin,$pass,$dbname);
	$query="Select * from users where username='$user' and upass='$upass'";	
	$result=mysql_query($query);
	if(($row=mysql_fetch_array($result)))
	{	

		if($upass==$row['upass'] && upass!="")
		{
		return 1;
		}
		else
		return 0;		


	}



}

function connectToDb($server,$user,$pass,$database)
{

	$s=mysql_connect($server,$user,$pass);
	$d=mysql_select_db($database,$s);

	if(!$s || !$d)
	return false;
	else
	return true;
}


function GetCartId()
{
	if(isset($_COOKIE["cartId"]))
	{
		return $_COOKIE["cartId"];

	}
	else
	{
		session_start();
		setcookie("cartId", session_id(), time+((3600 * 24) * 30));
		return session_id();

	}

}
?>	


this is db.php

 

and then login.php

<?
include ("db.php");
if(authenticateUser($username,$upass))
{
	setcookie("cookie_passwd",$upass);
	setcookie("cookie_user",$uname);
	header("Location:Http://localhost/cart/list.php");
		exit;
}

else
{

		header("Location:http://localhost/cart/index.php");
		exit();
}





?>

I'm not too clear on exactly what your problem is, but I see a few things you need to fix:

 

1) Don't use:

 

<?

 

for an opening tag, use:

 

<?php

 

The first one can cause problems sometimes, as browsers will sometimes parse it as XML instead of PHP, depending on your settings.

 

2) You are passing $username and $upass to the function authenticateuser, but you haven't set those variables anywhere.

 

3) You are storing the user's password in a cookie. VERY dangerous - anyone who uses that computer can go in and see the users password quickly and easily. You shouldn't do this.

 

 

As I said, I don't really understand your problem. But I kind of suspect that its #2 of my list.

well those are passed from the login page which is just the html file whose code is as follows

<html>
<head>
<title>Test Page</title>
</head>
<body>
<table width="100%" height="2">
<tr><td><font size="-2">Login Page</font></td></tr>
</table>
<form action="login.php" method="post">
Login Name: <input type="text" name="username">
Password: <input type="password" name="upass">
<input type="submit" value="Login">


</form>


</body>


</html>

the problem is that page is not redirecting...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.