URL encoding decoding or nothing at all

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ziggy
Forum Newbie
Posts: 3
Joined: Thu Jun 26, 2003 12:06 pm
Location: Colorado Springs, CO USA

URL encoding decoding or nothing at all

Post 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!
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post 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
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

why not switch from the deprecated $HTTP_GET_VARS['variable'] to the non-deprecate $_GET['variable']?
ziggy
Forum Newbie
Posts: 3
Joined: Thu Jun 26, 2003 12:06 pm
Location: Colorado Springs, CO USA

Thanx m3rajk & hedge

Post 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)
ziggy
Forum Newbie
Posts: 3
Joined: Thu Jun 26, 2003 12:06 pm
Location: Colorado Springs, CO USA

It worked!

Post 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!
Post Reply