hi

I have this URL:

page.php?section=book +10

and this code:


$section=$_REQUEST["section"];
echo $section;

this output is: book 10
but it must be: book +10

what do I do?

thanks

    The URL is one of the elements of the $_SERVER array.

      How do you prepare the URL on the page? Do you use [man]urlencode[/man]?

        When you add some query string data to your request url like so:
        http://example.com/mypage.php?some_variable_name=a+string+goes+here

        Then you should note that you can't really use spaces in the url or query string or it 'breaks' it. Certain other characters also break urls like page breaks, tabs, etc. Also, certain parts of a url are expected to be interpreted as path delimiters or part of the domain and so on. This has a lot to do with the HTTP protocol (exactly how eludes me at the moment but I'm sure weedpacket will know) but the basic idea is that occasionally you need to specify a character in your url that is going to break it -- i.e., render it unworkable for an actual http request. One particular case is when you specify spaces in your query string. There's an RFC that discusses all of this ad nauseam.

        The long story short here is that a + character is how spaces get encoded when you want to put them in a url. If you didn't encode the spaces, it would probably break something somewhere. Wikipedia has a sort of meandering article about it.

        If any of that makes any sense to you, then it might make sense that this url is 'broken' because it contains a space before the plus
        page.php?section=book +10

        it should also make sense that if one is to [man]urldecode[/man] the string "book +10" then the plus character becomes a space character which yields "book 10".

        If you are responsible for generating this urls and creating links with them on your site, then you should make sure you [man]urlencode[/man] the strings that you are assigning to "section" before you create the url. For example, if your script has the section value you want to build a url from in the variable $section, you should do this:

        $section = "book +10"; // we've assigned this string to a variable! note the space and plus sign
        $my_url = "page.php?section=" . urlencode($section); // this will replace any chars in $section that migh want to break your url before we put them in our url
        
          Write a Reply...