Jump to content

Redirect in PHP


Heba

Recommended Posts

[!--fonto:Century Gothic--][span style=\"font-family:Century Gothic\"][!--/fonto--]Hi there

I've learnt that [b]header('Location: URL'');[/b]
is like [b]Response.redirect [/b] in ASP

So i tried to do this code but it doesnt work ...

[code]
<?php
if(isset($_POST['submit']) && $_POST['submit'] == 'Submit') //if form has been submitted
{
    $url = "http://localhost/Warehouse_Services_Operations_System/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>SYS</title>
.
.
.
.
...
.
.
.
.
.
.
<body>
<?php
if(!empty($denied))
{
echo $denied;
}
?>
.
.


...



.
.
.
.
.
.
.
</body>
</html>
[/code]

Can someone please enlighten me!




[!--fontc--][/span][!--/fontc--]
Link to comment
Share on other sites

Try this. I think that header() won't let you use variables inside its ( ).

[code]
<?php
if(isset($_POST['submit']) && $_POST['submit'] == 'Submit') //if form has been submitted
{
    $denied = "";
    $name = $_POST['name'];
    $pass = $_POST['pass'];
    if ($name == "Heba" &&  $pass == "123")
    {
        header("Location: Warehouse_Services_Operations_System/main.php"); /* 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>SYS</title>
.
.
.
.
...
.
.
.
.
.
.
<body>
<?php
if(!empty($denied))
{
echo $denied;
}
?>
.
.
...
.
.
.
.
.
.
.
</body>
</html>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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