0
//Grab and assign List ID from confirmation URL 
$L = $_GET["L"]; 

//Set Redirects based on List ID  
if($L == "1") { 
header("Location: http://stat.domain.com/");
exit();
}  

This is the content of a redirection rule that I have created, but I am thinking of putting these in a separate file instead of the master file MASTER.php. I was reading online and there are different ways of reading the content off a separate file, of which are functions like include() include_once(). However, after reading through some information online, i am still not very sure what i should do to include the above content in the master file.

Any efficient way of doing this?

Ting Ping
  • 1,145
  • 7
  • 18
  • 34
  • yes you could just `include();` it. Take care of the `headers already sent` warnings. – Sebas Feb 17 '13 at 14:11
  • If this must be executed in MASTER.php, then `include 'thisfile.php';` See http://stackoverflow.com/questions/3546160/include-include-once-require-or-require-once for the differences. – Michael Berkowski Feb 17 '13 at 14:11

1 Answers1

1

You only want to include that file once in a certain place. Perhaps add an include to redirects.php from master.php:

require_once 'redirects.php';

You could also use include_once, but that will not halt the script if the file cannot be found and will fail silently - which is usually much worse than explicitly.

Aram Kocharyan
  • 20,165
  • 11
  • 81
  • 96
  • Hi, so i should insert the following code to my master.php: require_once "redirects.php"; is that right? – Ting Ping Feb 17 '13 at 14:15
  • Yes, up the top before any other code is executed to ensure nothing is written to output beforehand. – Aram Kocharyan Feb 17 '13 at 14:17
  • Must it be all the way at the top or could I insert it in the same line where the previous codes were located? – Ting Ping Feb 17 '13 at 14:19
  • Basically you can't write anything before the `header` call. If you do so accidentally the redirect will fail, and you may not be aware of it until users experience it or you test it, so it's a good idea to put it somewhere at the top or ensure there won't be output when it's called. – Aram Kocharyan Feb 17 '13 at 14:29