urldecode

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


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-10-2003
Martin Cunningham
 
Posts: n/a
Default urldecode

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/



Reply With Quote
  #2 (permalink)  
Old 07-10-2003
Andrew G
 
Posts: n/a
Default Re: urldecode


"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


Reply With Quote
  #3 (permalink)  
Old 07-10-2003
Martin Cunningham
 
Posts: n/a
Default Re: urldecode

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
>
>



Reply With Quote
  #4 (permalink)  
Old 07-10-2003
Andrew G
 
Posts: n/a
Default Re: urldecode


"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;









Reply With Quote
  #5 (permalink)  
Old 07-10-2003
Martin Cunningham
 
Posts: n/a
Default Re: urldecode

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;
>
>
>
>
>
>
>
>
>



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:56 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0