Page 1 of 1

URL encoding decoding or nothing at all

Posted: Thu Jun 26, 2003 12:06 pm
by ziggy
Ok guyz I have good one for you! see if you can figure this one out :roll:

I have a select box e.g.

Code: Select all

<form name='test' method=GET action='process.php'>
....// some query... get records start while loop

$varfromphpscript = '$id&name=$name&whatever=$what';
while loop begins &#123; ?>
<select name="select">
 <option value='<?php echo $varfromphpscript; ?>'><?php echo $varnamefromphpscript ?></option>
.....
</select>
<?php &#125; //while loop ends ?>
</form>
The while loop assigns values in select menu...

Now I am using GET form method to post the form values to another page, the VALUE in select menu is URL strings, e.g. $id&name=$name constructs the URL to what I want i.e. http://www.whatever.com/process.php?sel ... gy&what=no

which when posted gets encoded and changes to http://www.whatever.com/process.php?sel ... 2what%3Dno

NOW on process.php (the target page) i tried to be smart and used urldecode() to decoded the URL, back to the way it should be! like this>>

$url = $HTTP_SERVER_VARS["HTTP_HOST"] . $HTTP_SERVER_VARS["REQUEST_URI"];

$url = urldecode($url);


Now the question is how do I extract the URL parameters which I use to get easily with $HTTP_GET_VARS[], but now I have the URL in $url,

OR

how to keep from URL getting encoded in first place?
As for why do I have to post all these values via select menu! well all I can say is... I just have to!

Posted: Thu Jun 26, 2003 12:46 pm
by hedge
I think this may help you, this command parses a string into vars for you

http://www.php.net/manual/en/function.parse-str.php

Posted: Thu Jun 26, 2003 2:36 pm
by m3rajk
why not switch from the deprecated $HTTP_GET_VARS['variable'] to the non-deprecate $_GET['variable']?

Thanx m3rajk & hedge

Posted: Thu Jun 26, 2003 3:49 pm
by ziggy
Well m3rajk I am using the $_GET too and thanx for pointing it out but that still does nothing to parse the string... i.e. the URL that I have in $url ... anyways hedge thanx for pointing me to the parse-str function, I will check it out .. and post back how it went

8)

It worked!

Posted: Thu Jun 26, 2003 7:28 pm
by ziggy
Ok thanx for your help guyz, this worked like a charm!
following URL:
http://www.whatever.com/processor.php?s ... Begin%3D11

decoded and parsed to extract:

$begin=120
$num=13
$numBegin=11
$mall=213

:)

Code: Select all

<?php 
// used to capture full URL
$url = $HTTP_SERVER_VARS&#1111;"HTTP_HOST"] . $HTTP_SERVER_VARS&#1111;"REQUEST_URI"];

// decoding the url and saving into $url
$url = urldecode($url);

//extracting all url variables
parse_str($url);
?>
Thanx for all your help!