0

I have a web page that should only be accessed if a 'Get' variable is set in the url. I use the isset function to check for the variable. If the variable is not set I want to redirect to another page.

My main page has the following code

//index.php
<!DOCTYPE html>
<?php 
require("php/loadSurvey.php");
require("php/saveSurvey.php");
checkGet(); 
?>
<html>
<head>
//some html stuff and closing tags

checkGet is a php function defined in loadSurvey.php:

//php/loadSurvey.php
function checkGet()
{
  if(!isset($_GET['ID'])) 
  {
     header("Location: http://kristophertadlock.com/passcode.php", true, 303);
     die();
  }
}

The index page should redirect to this page

//passcode.php
<!DOCTYPE html>
<html>
<p>
you got here
</p>
</html>

passcode.php exist in the same directory as the index.php. When I using something like mydomain/$ID=1 I get the web page to load just like it should. When I using something like mydomain/ I get a blank page instead of redirecting to my passcode page. Does anyone know what I am doing wrong? Thank you.

user3538411
  • 338
  • 4
  • 15
  • 4
    Most probable it is because you try to header after you sent some information to the browser already. Try using `checkGet()` before the `` tag. So like: ` – JiFus Oct 15 '14 at 20:04
  • 1
    If there is any output at all prior to using header commands it will fail. – Brian Oct 15 '14 at 20:07
  • 1
    If you put `ini_set('display_errors',1);error_reporting(E_ALL);` at the top of your PHP script, then errors will be printed and you can probably figure out what's wrong. But, there's about a 99.99% chance JiFus is correct. Also, if – Reed Oct 15 '14 at 20:07
  • Thanks Jifus, you were right. I had tried it the way you suggested first, but it wasn't working. I followed the link provided by Mark B and what I think happened is I accidently left a space in before my Php tags. It is behaving now, thank you guys for your help. – user3538411 Oct 15 '14 at 20:14

0 Answers0