Jump to content

[SOLVED] PHP Conditional Redirection


DeepakJ

Recommended Posts

basically you send them to a page, in this instance we'll call it redirect.php

 

if($variable1 == value){
header("Location: page1.php");
}elseif($variable2 == value2){
header("Location: page2.php");
}else{
echo "Error!";
}

 

If you told me what information was being bought to the page and how (by form, cookies etc..) I could be of more help

if ($_GET['verif']){
header("Location: trueverif.html");
}
elseif ($_GET['sinput']){
header("Location: truesinput.html");
}
elseif ($_GET['linput']){
header("Location: truelinput.html");
}
elseif ($_GET['vdata']){
header("Location: trueviewdata.html");
}
elseif ($_GET['rdata']){
header("Location: reportdata.php");
}

 

Why doesn't this code work then?

i just use javascript....

 

<?php 

if (condition){
     echo '<script>window.location = "page1.php"</script>';
} else if (condition2) {
     echo '<script>window.location = "page2.php"</script>';
} else {
     echo '<script>window.location = "page3.php"</script>';
}

?>

 

yours would be

 

if ($_GET['verif']){
echo '<script>window.location = "trueverif.html"</script>';
}
elseif ($_GET['sinput']){
echo '<script>window.location = "truesinput.html"</script>';
}
elseif ($_GET['linput']){
echo '<script>window.location = "truelinput.html"</script>';
}
elseif ($_GET['vdata']){
echo '<script>window.location = "trueviewdata.html"</script>';
}
elseif ($_GET['rdata']){
echo '<script>window.location = "reportdata.html"</script>';
}

Change your javascript so it includes the querystring:

 

<?php 

if (condition){
     echo '<script>window.location = "page1.php?verif"</script>';
} else if (condition2) {
     echo '<script>window.location = "page2.php?sinput"</script>';
} else {
     echo '<script>window.location = "page3.php?linput"</script>';
}

?>

This is what accesses it:

 

<html><head><title>AlibreCam Verification 

System</title></head>


<center>
<input type="submit" value="Verification" name = 

"verif">          
<input type="submit" value="Sales Input" name = 

"sinput">        
<input type="submit" value="License Input" name = 

"linput">         
<input type="submit" value="View Data" name = 

"vdata">         
<input type="submit" value="Report Data" name = 

"rdata">
</center>


</html>

 

 

read up on header().

http://us3.php.net/manual/en/function.header.php

 

You can not output ANYTHING (HTML, PHP print statements, etc) to the browser before you redirect with header(). If you want to redirect with it, make sure that it comes before any output to the browser.

Archived

This topic is now archived and is closed to further replies.

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