This is a discussion on urldecode within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi. I'm using a file as my error page, ie 403, 404 etc. What I want to do is ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi. I'm using a file as my error page, ie 403, 404 etc. What I want to do is
pass the error number to that page er error.php?err=404 and get the file to pick up the 404 and then process it in the file to get a desired output. I can't firstly get the value into the file from the url, secondly when i input a value directly into the file to test ie I insert this line $Error_Number = '404'; and i test to see if $Error_Number is = 403, 404 or 500. However no matter what I put in i get no result. The file as it is is included. ----------------------- <?php define('IN_PHPBB', true); $phpbb_root_path = './'; include($phpbb_root_path . '/extension.inc'); include($phpbb_root_path . '/common.'.$phpEx); $userdata = session_pagestart($user_ip, PAGE_VIEWONLINE); init_userprefs($userdata); define('$Error_Number', true); define('$Error_Message', true); //define('$err', true); //maybe?? $Error_Number = '403';//urldecode($err); echo $Error_Message; //end maybe?? if('$Error_Number' == 403){ $Error_Message = "You are not authorized to view this page.<br>You might not have permission to view this directory or page using the credentials you supplied."; } else if('$Error_Number' == 404){ $Error_Message = "The page cannot be found.<br>The page you are looking for might have been removed, had its name changed, or is temporarily unavailable."; } else if('$Error_Number' == 500){ $Error_Number = 500; $Error_Message = "The page cannot be displayed.<br>There is a problem with the page you are trying to reach and it cannot be displayed."; } $page_title = "Error " . $Error_Number; include($phpbb_root_path . 'includes/page_header.'.$phpEx); $template->set_filenames(array('body' => 'error_body.tpl')); $template->pparse('body'); include($phpbb_root_path . 'includes/error_tail.'.$phpEx); ?> ----------------------- Please please please help. -- Martin Cunningham. Macro-Tek http://www.macro-tek.cjb.net/ |
|
|||
|
"Martin Cunningham" <muttly@iol.ie> wrote in message news:beidkq$36e$1@kermit.esat.net... > $Error_Number = '403';//urldecode($err); This may not be the problem but when you initialise a variable using quotes as you have here, you are defining your error "number" as a string. I think it's bad programming style to have a variable called $Error_Number that is in fact a string. > if('$Error_Number' == 403){ > $Error_Message = "You are not authorized to view this page.<br>You might > not have permission to view this directory or page using the credentials you > supplied."; > } Same story here, You don't need the quotes around the variable name but you do need the quotes around 403 because you have previously defined it as a string. So to sum up try either: $Error_Number = 403; if($Error_Number == 403){ $Error_Message = "You are not authorized to view this page.<br>You might not have permission to view this directory or page using the credentials you supplied."; } Or this: $Error_Number = '403'; if($Error_Number == '403'){ $Error_Message = "You are not authorized to view this page.<br>You might not have permission to view this directory or page using the credentials you supplied."; } The first stores $Error_Number as an integer value as far as PHP is concerned and the second stores $Error_Number as a string. I think the first is preferable. HTH Andrew |
|
|||
|
Ok. I've done that but it still desn't do what I want. The url would be
http://www.somewhere.com/forum/error.php?err=404 I want to get the err=404 part of that url in to my file. I believe that to do that you must decode the url but all i get as a value then is "Array" and that definaetly isn't 404. ----------------------- define('$Error_Number', true); define('$Error_Message', true); //maybe?? $Error_Number = urldecode($err); //HERES THE PROBLEM //end maybe?? if($Error_Number == '403'){ $Error_Message = "You are not authorized to view this page.<br>You might not have permission to view this directory or page using the credentials you supplied."; } else if($Error_Number == '404'){ $Error_Message = "The page cannot be found.<br>The page you are looking for might have been removed, had its name changed, or is temporarily unavailable."; } else if($Error_Number == '500'){ $Error_Number = 500; $Error_Message = "The page cannot be displayed.<br>There is a problem with the page you are trying to reach and it cannot be displayed."; } $page_title = "Error " . $Error_Number; include($phpbb_root_path . 'includes/page_header.'.$phpEx); ------------------------- -- Martin Cunningham. Macro-Tek http://www.macro-tek.cjb.net/ "Andrew G" <fungus@DONOTSPAM.hunterlink.net.au> wrote in message news:0x3Pa.5$sI.8358@nasal.pacific.net.au... > > "Martin Cunningham" <muttly@iol.ie> wrote in message > news:beidkq$36e$1@kermit.esat.net... > > > $Error_Number = '403';//urldecode($err); > > This may not be the problem but when you initialise a variable using quotes > as you have here, you are defining your error "number" as a string. I think > it's bad programming style to have a variable called $Error_Number that is > in fact a string. > > > if('$Error_Number' == 403){ > > $Error_Message = "You are not authorized to view this page.<br>You might > > not have permission to view this directory or page using the credentials > you > > supplied."; > > } > > Same story here, You don't need the quotes around the variable name but you > do need the quotes around 403 because you have previously defined it as a > string. > > So to sum up try either: > > $Error_Number = 403; > if($Error_Number == 403){ > $Error_Message = "You are not authorized to view this page.<br>You might > not have permission to view this directory or page using the credentials > you > supplied."; > } > > > > Or this: > > > > $Error_Number = '403'; > if($Error_Number == '403'){ > $Error_Message = "You are not authorized to view this page.<br>You might > not have permission to view this directory or page using the credentials > you > supplied."; > } > > > The first stores $Error_Number as an integer value as far as PHP is > concerned and the second stores $Error_Number as a string. > > I think the first is preferable. > > HTH > Andrew > > |
|
|||
|
"Martin Cunningham" <muttly@iol.ie> wrote in message news:beihn0$4of$1@kermit.esat.net... > Ok. I've done that but it still desn't do what I want. The url would be > http://www.somewhere.com/forum/error.php?err=404 I want to get the err=404 > part of that url in to my file. I believe that to do that you must decode > the url but all i get as a value then is "Array" and that definaetly isn't > 404. > > $Error_Number = urldecode($err); //HERES THE PROBLEM You do not need to use the urldecode function. You should already have access to that variable in your script and it will be called $err. If that does not work then you probably have the "register_globals" variable set to "off". That is a good thing for security. (look for register_globals in the php.ini file and read more here: http://www.php.net/register_globals ) So, if you have register_globals set to "off" the above line needs to be: $Error_Number = $_GET['err']; Otherwise: $Error_Number = $err; |
|
|||
|
Thats perfect. Thanks you very much Andrew. I used $Error_Number =
$_GET['err']; as the other one didn't work. Thanks again. -- Martin Cunningham. Macro-Tek http://www.macro-tek.cjb.net/ "Andrew G" <fungus@DONOTSPAM.hunterlink.net.au> wrote in message news:2d4Pa.8$sI.8406@nasal.pacific.net.au... > > "Martin Cunningham" <muttly@iol.ie> wrote in message > news:beihn0$4of$1@kermit.esat.net... > > Ok. I've done that but it still desn't do what I want. The url would be > > http://www.somewhere.com/forum/error.php?err=404 I want to get the err=404 > > part of that url in to my file. I believe that to do that you must decode > > the url but all i get as a value then is "Array" and that definaetly isn't > > 404. > > > > > $Error_Number = urldecode($err); //HERES THE PROBLEM > > You do not need to use the urldecode function. You should already have > access to that variable in your script and it will be called $err. If that > does not work then you probably have the "register_globals" variable set to > "off". That is a good thing for security. (look for register_globals in the > php.ini file and read more here: http://www.php.net/register_globals ) > > So, if you have register_globals set to "off" the above line needs to be: > > $Error_Number = $_GET['err']; > > Otherwise: > > $Error_Number = $err; > > > > > > > > > |
![]() |
| Thread Tools | |
| Display Modes | |
|
|