Jump to content


Photo

Redirect in PHP


  • Please log in to reply
5 replies to this topic

#1 Heba

Heba
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 28 February 2006 - 10:40 AM

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

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

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

<?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>

Can someone please enlighten me!




[!--fontc--][/span][!--/fontc--]

#2 loki_racer

loki_racer
  • Members
  • Pip
  • Newbie
  • 3 posts

Posted 28 February 2006 - 04:53 PM

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

<?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>

Chris Thompson
www.thompsonbd.com

"It's time to roll the dice."

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 28 February 2006 - 06:04 PM

No, you can use variable within a header() function.

To the OP ... what indications do you get that it doesn't work? Errors?

Ken

#4 Heba

Heba
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 01 March 2006 - 04:36 AM

ok when i did that it worked but it gives me an empty window with no messages!

#5 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 01 March 2006 - 04:49 AM

Error reporting may be disabled in your php.ini file.

PM me and link me...and I will solve all your problems. :-P
PHP Ninja

#6 Heba

Heba
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 01 March 2006 - 06:00 AM

SOLVED :D

Thank you all




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users