View Single Post
Old 11-14-2012, 12:39 PM   PM User | #16
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
Firepages is right, logic like that is behind a lot of your problems. Consider your idea: You set up everything like it's an error, and only do the final outcomes depending on if it actually is. Hopefully, for the vast majority of times, your result will not be an error. You will not need an error set up in these cases, but you will still burdening your script with the assumption that it will be. Meaning this script could be running a lot smoother for pages not generating an error. You shouldn't need to assume anything in a good script.

It should be this simple..

In a main file:
PHP Code:


  
if( !isset($_GET['section']) || strlen($_GET['section']) == 0) { 

  
$_SESSION['Error'] = 2422// Some error number, or something. 

   
header("Location: "BASE_URL ."/account/results.php");  } 
In the results file:
PHP Code:


  
// Check if an error has been set.
  
if( isset($_SESSION['Error'])) && $_SESSION['Error'] != 0) {

     switch(
$_SESSION['Error']){ // Find what error it is.

      
case 2422: echo "Error: No section defined in "$_ENV['REQUEST_URI']; break;

  
// Add new cases for any self-defined error you may use.

      
default: echo "No error was defined."; break;

  } } 
1 ). You wouldn't echo the message like that, that's just for simple example. If it was me I would call a function there that would then handle logging and emailing. Well, if it was me I wouldn't be doing anything like this, lol.

2 ). Your calculation on $_GET['section'] is completely ineffective, and wouldn't trigger your error handling if it was a empty string (but still set), or actually existed. Meaning your check is doing next to nothing to actually catch what you're trying to catch. I could change your url to /your_file.php?section=, or even /your_file.php?section=anything and your check would do nothing to stop that. Depending on how you're using $_GET['section'] after this check you may have a massive security hole there.

3 ). If I recall right, using header(Location: ) will return a redirect response code, and will preserve the original page location in the environment variable $_ENV['REQUEST_URI']. You should be able to use that instead of remembering $_SERVER['SCRIPT_NAME'] from the last page.

4 ). You are doing a lot of writing and asking a lot of questions. This isn't necessarily bad, but you're making it hard for anyone to help you. If you are serious about fixing your problems you should consider taking some of the previous advice to heart, and going to the PHP documentation or Google and doing a bit of reading. A little more effort to understand what is being suggested could go a long way, and save you more time in the end.

Last edited by Custard7A; 11-14-2012 at 12:42 PM.. Reason: No brackets on switch. Whacked this together bit hastly.
Custard7A is offline   Reply With Quote