urlencode and $_GET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • meltedown

    urlencode and $_GET

    urlencode turns # into %23
    When I sent it thru $_GET, it dissapears, along with anything that comes
    after it.

    for example:
    urlencode turns
    HOYDM_EXC_#4_NA T
    into HOYDM_EXC_%234_ NAT

    When I use it in an url
    index.php?id=HO YDM_EXC_%234_NA T

    $_GET[id]=HOYDM_EXC_

    Am I doing something wrong ?
  • Erwin Moller

    #2
    Re: urlencode and $_GET

    meltedown wrote:

    Hi,
    [color=blue]
    > urlencode turns # into %23[/color]

    Yes.
    [color=blue]
    > When I sent it thru $_GET, it dissapears, along with anything that comes
    > after it.[/color]

    What does that mean?
    "sending through $_GET" ???
    Do you mean you use some URL?

    You do not send anything through $_GET, you use $_GET to retrieve values
    encoded in GET.
    [color=blue]
    >
    > for example:
    > urlencode turns
    > HOYDM_EXC_#4_NA T
    > into HOYDM_EXC_%234_ NAT
    >[/color]

    yes.
    [color=blue]
    > When I use it in an url
    > index.php?id=HO YDM_EXC_%234_NA T
    >
    > $_GET[id]=HOYDM_EXC_
    >
    > Am I doing something wrong ?[/color]

    Yes.

    If you want the value of 'id' from the URL (GET) use:

    $bla = $_GET["id"];

    Regards,
    Erwin Moller

    Comment

    • black francis

      #3
      Re: urlencode and $_GET

      try NOT encoding the original url (it's the browser's job), but DO
      decode the "incoming" url.

      Comment

      • meltedown

        #4
        Re: urlencode and $_GET

        Erwin Moller wrote:[color=blue]
        > meltedown wrote:
        >
        > Hi,
        >
        >[color=green]
        >>urlencode turns # into %23[/color]
        >
        >
        > Yes.
        >
        >[color=green]
        >>When I sent it thru $_GET, it dissapears, along with anything that comes
        >>after it.[/color]
        >
        >
        > What does that mean?
        > "sending through $_GET" ???
        > Do you mean you use some URL?
        >
        > You do not send anything through $_GET, you use $_GET to retrieve values
        > encoded in GET.[/color]

        And how does it get there- you send it there. So you are sending it
        throught $_GET[color=blue]
        >
        >[color=green]
        >>for example:
        >>urlencode turns
        >>HOYDM_EXC_#4_ NAT
        >>into HOYDM_EXC_%234_ NAT
        >>[/color]
        >
        >
        > yes.
        >
        >[color=green]
        >>When I use it in an url
        >>index.php?id= HOYDM_EXC_%234_ NAT
        >>
        >>$_GET[id]=HOYDM_EXC_
        >>
        >>Am I doing something wrong ?[/color]
        >
        >
        > Yes.
        >
        > If you want the value of 'id' from the URL (GET) use:
        >
        > $bla = $_GET["id"];[/color]

        Yes of course I know that- I'm not talking about getting the value from
        $_GET. I am saying that the value of $_GET is equal to "HOYDM_EXC_ ". Its
        obvious what I meant. The point is, the end of the string is missing.
        Do you now whether this is a common problem ?[color=blue]
        >
        > Regards,
        > Erwin Moller
        >[/color]

        Comment

        • meltedown

          #5
          Re: urlencode and $_GET

          black francis wrote:[color=blue]
          > try NOT encoding the original url (it's the browser's job), but DO
          > decode the "incoming" url.
          >[/color]
          I tried this even though it doesn't make any sense.
          Browsers don't do anything to #. As far as I can see, it is not the
          browsers job to encode anything in the url. #'s are not allowed in URLs.
          Thats what urlencode() is for, and it works fine. The question is: why
          doesn't %23 and everything after it make it to $_GET ?

          Comment

          • meltedown

            #6
            Re: urlencode and $_GET

            meltedown wrote:[color=blue]
            > black francis wrote:
            >[color=green]
            >> try NOT encoding the original url (it's the browser's job), but DO
            >> decode the "incoming" url.
            >>[/color]
            > I tried this even though it doesn't make any sense.
            > Browsers don't do anything to #. As far as I can see, it is not the
            > browsers job to encode anything in the url. #'s are not allowed in URLs.[/color]

            clarificatin: # are allowed in urls, but only as part of an anchor
            identifyer.
            [color=blue]
            > Thats what urlencode() is for, and it works fine. The question is: why
            > doesn't %23 and everything after it make it to $_GET ?[/color]

            Comment

            • Jerry Stuckle

              #7
              Re: urlencode and $_GET

              meltedown wrote:[color=blue]
              > Erwin Moller wrote:
              >[color=green]
              >> meltedown wrote:
              >>
              >> Hi,
              >>
              >>[color=darkred]
              >>> urlencode turns # into %23[/color]
              >>
              >>
              >>
              >> Yes.
              >>
              >>[color=darkred]
              >>> When I sent it thru $_GET, it dissapears, along with anything that comes
              >>> after it.[/color]
              >>
              >>
              >>
              >> What does that mean?
              >> "sending through $_GET" ???
              >> Do you mean you use some URL?
              >>
              >> You do not send anything through $_GET, you use $_GET to retrieve
              >> values encoded in GET.[/color]
              >
              >
              > And how does it get there- you send it there. So you are sending it
              > throught $_GET
              >[color=green]
              >>
              >>[color=darkred]
              >>> for example:
              >>> urlencode turns
              >>> HOYDM_EXC_#4_NA T
              >>> into HOYDM_EXC_%234_ NAT
              >>>[/color]
              >>
              >>
              >> yes.
              >>
              >>[color=darkred]
              >>> When I use it in an url
              >>> index.php?id=HO YDM_EXC_%234_NA T
              >>>
              >>> $_GET[id]=HOYDM_EXC_
              >>>
              >>> Am I doing something wrong ?[/color]
              >>
              >>
              >>
              >> Yes.
              >>
              >> If you want the value of 'id' from the URL (GET) use:
              >>
              >> $bla = $_GET["id"];[/color]
              >
              >
              > Yes of course I know that- I'm not talking about getting the value from
              > $_GET. I am saying that the value of $_GET is equal to "HOYDM_EXC_ ". Its
              > obvious what I meant. The point is, the end of the string is missing.
              > Do you now whether this is a common problem ?
              >[color=green]
              >>
              >> Regards,
              >> Erwin Moller
              >>[/color][/color]

              Can you post your code?

              I've encoded a '#' before with no problems at all.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • M. Trausch

                #8
                Re: urlencode and $_GET

                meltedown wrote:[color=blue]
                >
                > clarificatin: # are allowed in urls, but only as part of an anchor
                > identifyer.
                >[color=green]
                >> Thats what urlencode() is for, and it works fine. The question is: why
                >> doesn't %23 and everything after it make it to $_GET ?[/color]
                >[/color]

                That's because the browser treats %23 as #... e.g., you cannot use that
                character, as it's local to the browser as a named-anchor. Use a
                different character. The browser treats all URL escaped characters *as
                the character it is*, so you can encode spaces and ~ and all sorts of
                other things into the URL.

                - Mike

                --
                Strip the obvious trash from the header to send e-mail.

                Comment

                • meltedown

                  #9
                  Re: urlencode and $_GET

                  Jerry Stuckle wrote:[color=blue]
                  > Can you post your code?
                  >
                  > I've encoded a '#' before with no problems at all.
                  >[/color]
                  Thanks for telling me that. Apparently, this not a common problem but
                  something wrong with my code. After you told me that, I did this simple
                  example.


                  After you hit the link, it says
                  $_GET is:Array ( [value] => start#end )
                  #end is not missing, so it works fine

                  Here's the code for the example
                  echo "\$_GET is:";
                  print_r($_GET);
                  echo "<br>\n";
                  $value="start#e nd";
                  echo "value is:$value<br>\n ";
                  $value=urlencod e($value);
                  echo "value after urlencode is:$value<br>\n ";
                  echo "<a href='?value=". $value."'>test link</a>";

                  I'm still trying to figure out how to make an example of the original
                  problem.

                  Comment

                  • Erwin Moller

                    #10
                    Re: urlencode and $_GET

                    meltedown wrote:

                    <snip>
                    [color=blue]
                    >
                    > And how does it get there- you send it there. So you are sending it
                    > throught $_GET[/color]

                    Well, I had the impression you didn't understand that part.
                    But appearantly you do.
                    [color=blue][color=green]
                    >>
                    >>[color=darkred]
                    >>>for example:
                    >>>urlencode turns
                    >>>HOYDM_EXC_#4 _NAT
                    >>>into HOYDM_EXC_%234_ NAT
                    >>>[/color]
                    >>
                    >>
                    >> yes.
                    >>
                    >>[color=darkred]
                    >>>When I use it in an url
                    >>>index.php?id =HOYDM_EXC_%234 _NAT
                    >>>
                    >>>$_GET[id]=HOYDM_EXC_[/color][/color][/color]

                    This part is where you confused me.
                    It looks like you want to ADD stuff to the $_GET-array, which doesn't make
                    much sense.

                    [color=blue][color=green][color=darkred]
                    >>>
                    >>>Am I doing something wrong ?[/color]
                    >>
                    >>
                    >> Yes.
                    >>
                    >> If you want the value of 'id' from the URL (GET) use:
                    >>
                    >> $bla = $_GET["id"];[/color]
                    >
                    > Yes of course I know that- I'm not talking about getting the value from
                    > $_GET. I am saying that the value of $_GET is equal to "HOYDM_EXC_ ". Its
                    > obvious what I meant. The point is, the end of the string is missing.
                    > Do you now whether this is a common problem ?[/color]

                    I do not see the problem to be honest.
                    I just tested on my own machine (PHP5) the follwing:



                    from php.test:

                    $id = $_GET["id"];
                    // ID now contains HJUYH_#4_NAT

                    Which is excactly what is expected.

                    So show us some more code.

                    Regards,
                    Erwin Moller


                    Comment

                    • meltedown

                      #11
                      Re: urlencode and $_GET

                      M. Trausch wrote:[color=blue]
                      > meltedown wrote:
                      >[color=green]
                      >>clarificati n: # are allowed in urls, but only as part of an anchor
                      >>identifyer.
                      >>
                      >>[color=darkred]
                      >>>Thats what urlencode() is for, and it works fine. The question is: why
                      >>>doesn't %23 and everything after it make it to $_GET ?[/color]
                      >>[/color]
                      >
                      > That's because the browser treats %23 as #...[/color]
                      Right. but its a # which is not an anchor.
                      e.g., you cannot use that[color=blue]
                      > character, as it's local to the browser as a named-anchor. Use a
                      > different character. The browser treats all URL escaped characters *as
                      > the character it is*,[/color]
                      Yes that's what I want it to do.
                      You can use that charactar as something besided an anchor, as long as it
                      is encoded. See the example I just posted in this thread.

                      so you can encode spaces and ~ and all sorts of[color=blue]
                      > other things into the URL.
                      >
                      > - Mike
                      >[/color]

                      Comment

                      • Oli Filth

                        #12
                        Re: urlencode and $_GET

                        M. Trausch said the following on 17/11/2005 14:22:[color=blue]
                        > meltedown wrote:
                        >[color=green]
                        >>clarificati n: # are allowed in urls, but only as part of an anchor
                        >>identifyer.
                        >>
                        >>[color=darkred]
                        >>>Thats what urlencode() is for, and it works fine. The question is: why
                        >>>doesn't %23 and everything after it make it to $_GET ?[/color]
                        >>[/color]
                        >
                        > That's because the browser treats %23 as #... e.g., you cannot use that
                        > character, as it's local to the browser as a named-anchor.[/color]

                        What? No it doesn't.



                        --
                        Oli

                        Comment

                        • meltedown

                          #13
                          Re: urlencode and $_GET

                          Erwin Moller wrote:[color=blue]
                          >
                          > I do not see the problem to be honest.
                          > I just tested on my own machine (PHP5) the follwing:
                          >
                          > http://bla.bla.bla/test.php?id=HJUYH_%234_NAT
                          >
                          > from php.test:
                          >
                          > $id = $_GET["id"];
                          > // ID now contains HJUYH_#4_NAT
                          >
                          > Which is excactly what is expected.
                          >
                          > So show us some more code.
                          >
                          > Regards,
                          > Erwin Moller
                          >
                          >[/color]
                          Right, I believe you. I know what it is now. Its not a PHP problem, its
                          a mod rewrite problem. Sorry, I left it out because I was trying not to
                          complicate my explaination.

                          if I use

                          it works fine.

                          but if I use:

                          The last part gets tuncated into SANROSA_

                          Here's the rewrite rule :
                          RewriteRule ([^/]+)/([^/]+)\.html$ /item.php?id=$2& cname=$1

                          The second ([^/])+ is the culprit, but I'm not sure how to fix it.
                          Presumably, it doesn't recognize %

                          Right now I have fixed the problem with a hack
                          $id=preg_replac e("|#|",'_PDSGN _',$id);
                          So this example now looks like:




                          Comment

                          • Jerry Stuckle

                            #14
                            Re: urlencode and $_GET

                            meltedown wrote:[color=blue]
                            > Jerry Stuckle wrote:
                            >[color=green]
                            >> Can you post your code?
                            >>
                            >> I've encoded a '#' before with no problems at all.
                            >>[/color]
                            > Thanks for telling me that. Apparently, this not a common problem but
                            > something wrong with my code. After you told me that, I did this simple
                            > example.
                            >
                            > http://reenie.org/test/test16.php?value=start%23end
                            > After you hit the link, it says
                            > $_GET is:Array ( [value] => start#end )
                            > #end is not missing, so it works fine
                            >
                            > Here's the code for the example
                            > echo "\$_GET is:";
                            > print_r($_GET);
                            > echo "<br>\n";
                            > $value="start#e nd";
                            > echo "value is:$value<br>\n ";
                            > $value=urlencod e($value);
                            > echo "value after urlencode is:$value<br>\n ";
                            > echo "<a href='?value=". $value."'>test link</a>";
                            >
                            > I'm still trying to figure out how to make an example of the original
                            > problem.[/color]

                            Yes, it looks like it's doing exactly what it's supposed to do.

                            I suspect a logic problem in your code. Look at the URL in your browser
                            bar in your original code. It should have something like:

                            http://www.example.com?value=start%23end

                            If instead of the "%23" you have a "#", the problem is you didn't get it
                            encoded properly. OTOH, if it you have something like "?value=" or
                            "?value=sta rt" you probably didn't get the string concatenated properly.

                            You can also look at the HTML source for the page you're linking from.
                            There you should see:

                            <a href="http://www.example.com/testpage?value= start%23end">te st link</a>

                            These things can be difficult to find sometimes!

                            --
                            =============== ===
                            Remove the "x" from my email address
                            Jerry Stuckle
                            JDS Computer Training Corp.
                            jstucklex@attgl obal.net
                            =============== ===

                            Comment

                            • black francis

                              #15
                              Re: urlencode and $_GET

                              again, it's the browser the one who 'encodes' the url, not you.

                              try-n-see:
                              <a href="example.p hp?var=one word"> turns into
                              "example.php?va r=one+word" in the address bar.

                              what you should never use un a url is an ampersand (use &amp; instead
                              of &), any other character is encoded by the browser.

                              Comment

                              Working...