Redirect in PHP
Moderator: General Moderators
-
Dark_AngeL
- Forum Commoner
- Posts: 39
- Joined: Tue Feb 21, 2006 5:16 am
Redirect in PHP
Hi
I have a question in ASP we have Response.Redirect" ";
What do we use in PHP?
I have a question in ASP we have Response.Redirect" ";
What do we use in PHP?
-
Dark_AngeL
- Forum Commoner
- Posts: 39
- Joined: Tue Feb 21, 2006 5:16 am
This is what i did
If the name is Heba and pass is 123 i want to direct the user 2 main.php
Code: Select all
$url = "main.php";
if ($name == "Heba" && $pass == "123")
{
header('Location: $url'); /* Redirect browser */
exit;
?>
<?
}
else
{
echo ("Sorry. You are not authorized to access this page");
echo ("<br>"."Go <a href='Index.php'> Back </a>");
} ?>If the name is Heba and pass is 123 i want to direct the user 2 main.php
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
You need to specify the full URL for $url.
For example
videos.php would be somthing like http://www.mysite.com/videos.php.
For example
videos.php would be somthing like http://www.mysite.com/videos.php.
-
Dark_AngeL
- Forum Commoner
- Posts: 39
- Joined: Tue Feb 21, 2006 5:16 am
Code: Select all
$url = "http://localhost/Warehouse_Services_Operations_System/main.php"- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
Code: Select all
<?
$url = "main.php";
if ($name == "nicky" && $pass == "123")
{
header('Location:http://localhost/Warehouse_Services_Operations_System/'.$url); /* Redirect browser */
exit;
}
else
{
echo ("Sorry. You are not authorized to access this page");
echo ("<br>"."Go <a href='Index.php'> Back </a>");
} ?>or as feyd said you can do it like this.
Code: Select all
<?
$url = "http://localhost/Warehouse_Services_Operations_System/main.php";
if ($name == "nicky" && $pass == "123")
{
header("Location:$url"); /* Redirect browser */
exit;
}
else
{
echo ("Sorry. You are not authorized to access this page");
echo ("<br>"."Go <a href='Index.php'> Back </a>");
} ?>Ps. Localhost, will only work on your machine.
-
Dark_AngeL
- Forum Commoner
- Posts: 39
- Joined: Tue Feb 21, 2006 5:16 am
Oh thank you so much all
nickman013 I will be using a DB soon and i sure will need ur help
i am starting it easy now
nickman013 I will be using a DB soon and i sure will need ur help
i am starting it easy now
Last edited by Dark_AngeL on Tue Feb 28, 2006 12:59 am, edited 2 times in total.
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
No problem.
Database stuff like this is very simple. You just need to make a table and 2 fields. The rest is simple coding just like the one you made above. Also it is much more secure. But if you want to make your script you got now a lot more secure, use md5().
Database stuff like this is very simple. You just need to make a table and 2 fields. The rest is simple coding just like the one you made above. Also it is much more secure. But if you want to make your script you got now a lot more secure, use md5().
-
Dark_AngeL
- Forum Commoner
- Posts: 39
- Joined: Tue Feb 21, 2006 5:16 am
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
-
Dark_AngeL
- Forum Commoner
- Posts: 39
- Joined: Tue Feb 21, 2006 5:16 am
here is what i did but still it doesnt work
it gives me an empty page with no message:(
it gives me an empty page with no message:(
Code: Select all
<?php
if(isset($_POST['submit']) && $_POST['submit'] == 'Submit') //if form has been submitted
{
$url = "main.php";
$denied = "";
$name = $_POST['name'];
$pass = $_POST['pass'];
if ($name == "Heba" && $pass == "123")
{
header('Location: '.$url.''); /* Redirect browser */
exit;
}
else {
$denied = "Sorry. You are not authorized to access this page<br>Go <a href='index.php' onclick='history.go(-1);return false'> Back </a>";
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>TITLE</title>
<body>
<?php
if(!empty($denied))
{
echo $denied;
}
?>
</body>
</html>- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
The url used in the header must be a FULL url. This means your $url="main.php" needs to be $url="http://www.yourwebside.com/main.php" before it can work.
-
Dark_AngeL
- Forum Commoner
- Posts: 39
- Joined: Tue Feb 21, 2006 5:16 am