I have a PHP code and that works fine on localhost on my laptop. The configuration is - Apache 2. PHP 4.4.5 But when I try to make it work on the hosting site, it does not. The page doe snot get redirected. header("Location: http://www.xxx.com/"); I have tried different ways to redirect the form but nothing works. Is there something with the php.ini settings?
Ensure that your start php tag are the first item in the script: For example line 1 <? line 2 header("Location: http://www.xxx.com/"); line 3 exit(); line 4 ?> NOT line 1 line 2 <? line 3 header("Location: http://www.xxx.com/"); line 4 exit(); line 5 ?>
$sql = "SELECT * FROM user WHERE userid = '$uid' AND password = '$pwd'"; $result = mysql_query($sql); if (!$result) { error('A database error occurred while checking your '. 'login details.\\nIf this error persists, please '. 'contact you@example.com.'); exit ;} if (mysql_num_rows($result) == 0) { unset($_SESSION['uid']); unset($_SESSION['pwd']); ?> <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> Access Denied </title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <h1> Access Denied </h1> <p> Your user ID or password is incorrect, or you are not a registered user on this site. To try logging in again, click <a href="<?=$_SERVER['PHP_SELF']?>">here</a>. To register, click <a href="signup.php">here</a>.</p> </body> </html> <?php exit; } [B] $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'location.php'; header("Location: http://$host$uri/$extra"); [/B] ?> Code (markup): I have the code like this, redirecting is on conditional basis.
I am not too good with web developement. But how can I use meta tags on conditional basis. I should split the form and then use meta tags in one form?
Try echo the address variables so you can make sure they are set properly. Also combine them before you put them into the location: bit.
No error messages although I have error_reporting ON. And it works on my PC running on windows XP and not on the hosting site.
sure just use if (condition) echo'<meta http-equiv="refresh" content="0;url=http://www.******.com'">';
degy is correct - you could use that. The main reason why the header would not work is if you are OUTPUTTING information to the user screen already (this could be a blank space) Check to make sure that is not the case. Also, echo the values of the http:// address in the header function, make sure it is not blank.
Thanks. It is able to redirect now. But I have another problem . It does not take the session value. I have stored uid in session. $_SESSION['uid'] = $uid; and trying to echo $_SESSION['uid'] after redirecting t another page. I have session_start() at the start of the page.
I did check (displayed) the address and other details in the header and as I see everything is correct
try if(isset($_SESSION["status"])) { }else{ session_start(); $_SESSION["status"]=1; } so you'll only start new session if session doesn't exist