Web Hosting Talk







View Full Version : Redirect a page


mithilesh
01-24-2002, 02:07 PM
I want to redirect a page by using If condition.

e.g
If ( True)
{
open a page ("http://www.php.net")
}
else

{
go to another page .
}

How can I do it.

Thank you

Smirks
01-24-2002, 02:30 PM
Using what? Apache? PHP? CGI? What condition must be met?

The Prohacker
01-24-2002, 03:08 PM
For PHP:


<?php
if ($var == "this")
header("Location: "http://www.php.net/");
}else if{
header("Location: "http://www.php.net/");
}
?>



Would be something like that, but unless we know what you need it for, I can't be sure...

mithilesh
01-24-2002, 03:42 PM
I am using Apache and php. Mr. The Prohacker You understood the my problem and what you suggest I have tried it .It doesn't shows any error but not redirect the page to proper location.It displays just a blank home page of php in which I have written this code .
In this case i have written the all code in login.php and my redirecting pages are welcome.php and wrong.php but when run the code it shows the blank page of login.php

Thank you

The Prohacker
01-24-2002, 04:18 PM
<?php
if ($var == "this")
header("Location: "http://www.php.net/");
} else {
header("Location: "http://www.php.net/");
}
?>




Use that... Sorry, I'm sick, and wasn't thinking.....

Noldar
01-24-2002, 04:18 PM
Why don't you post the code that you have.

I've done a website that requires a login and works in a very similar manner. I'm sure someone will be able to help you if you provide more info.

Richard

allan
01-24-2002, 04:25 PM
Originally posted by The Prohacker

header("Location: "http://www.php.net/");


Pro -- I thnk you have too many quotes in those lines, shouldn't it be:


header("Location: http://www.php.net/");

mithilesh
01-24-2002, 05:21 PM
Mr. Noldar Here I am writing the code .


<?
$dbh=mysql_connect("localhost","classica_cart","cart") or die ('I cannot connect to the data base');
mysql_select_db("classica_shop");
$query="SELECT * FROM members WHERE name='$name' AND passwd='$passwd'" ;
$result=mysql_query($query,$dbh);
$row=mysql_fetch_row ($result);
if ($row)
{
header("Location: http://www.classicsoftwares.biz/welcome.php");
exit;
}
else
{
header("Location: http://www.classicsoftwares.biz/wrong.php");
exit;
}
?>

mithilesh
01-24-2002, 05:38 PM
The page shows the following error Now

Warning: Cannot add header information - headers already sent by (output started at http://www.classicsoftwares.biz\login.php:3) in
http://www.classicsoftwares.biz\login.php on line 11

ffeingol
01-24-2002, 06:28 PM
You don't need the two exits.


<?
$dbh=mysql_connect("localhost","classica_cart","cart") or die ('I cannot connect to the data base');
mysql_select_db("classica_shop");
$query="SELECT * FROM members WHERE name='$name' AND passwd='$passwd'" ;
$result=mysql_query($query,$dbh);
$row=mysql_fetch_row ($result);
if ($row)
{
header("Location: http://www.classicsoftwares.biz/welcome.php");
}
else
{
header("Location: http://www.classicsoftwares.biz/wrong.php");
}
?>


The script will exit because it's done ;)

Frank

zupanm
01-24-2002, 06:44 PM
you are getting those errors cause you sent text to the browser before your header. The main cause it a blank spave before your <? or <?php line. If any text is sent before a header(), the header() will not work

mithilesh
01-25-2002, 01:58 PM
Thanks Mr. zupanm For your help now it is working properly .


:D