Wrox Programmer Forums
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 24th, 2004, 01:29 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default ?this=that

Just curious....

I'm not sure where to post this, but I'll try here.

What if one of the parameters in the address bar (?this=that) references to a page that needs parameters?

Ex:

http://localhost/mypage?one=one&two=...ng&three=three

Some of the above parameters are for the first page, but some are for the page that the first page references to....?

Is there some kind of escape or something? Like %91 or %20 or something?

Thanks,

----------
---Snib---
----------

<><
__________________
-Snib - http://www.snibworks.com
Where will you be in 100 years?
 
Old March 28th, 2004, 08:37 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Use a url encoding mechanism on the entire second URL.

For instance in PHP you'd use: urlencode(), urldecode()

If you're doing this client-side with JavaScript then the escape / unescape / encodeURI / decodeURI / encodeURIComponent / decodeURIComponent methods would be used, depending on platform and encoding needs.

The second URL might have URL encoded characters already, no worries though, if using PHP each will be encoded again, decode the entire URL string, then decode each individual value, where necessary. If using JavaScript you'll need to use the escape method twice, or the encodeURI method for the first encoding, then encodeURIComponent for the entire URL.

Here's a brief demonstration:
Code:
<?php

    $url  = urlencode('http://localhost/mypage?param=thing&otherparam=otherthing&three=three+four');

    // Whole URL
    echo 'http://localhost/mypage?one=one&two='.$url.'<br />';

    // Just the second URL decoded
    echo urldecode($url).'<br />';

?>
Outputs:
http://localhost/mypage?one=one&two=...3Dthree%2Bfour
http://localhost/mypage?param=thing&...ree=three+four

: )
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.