SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2011
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Two $_GET in one query string?

    Hello,

    What would happen if I ever end up with a utl like this?

    Code:
    http://somesite.com/?var1=blah&var2=ok?someothervar=test
    I am asking because I am making a redirect appending this bit to the incoming url: ?someothervar=test

    My question is obviously: what happens if the incoming url already has a querystring (such as ?var1=blah&var2=ok) and I append to it ?someothervar=test ? Should I test for every incoming request to check if a querystring already exists?

    Cheers.


  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See print_r($_GET); to see what it gives you:
    PHP Code:
    print_r($_GET); 
    It will return you:
    Array ( [var1] => blah [var2] => ok?someothervar=test )
    Instead you should do something like this:
    PHP Code:
    $url 'http://somesite.com/?var1=blah&var2=ok'// your existing url

    // now you can append it like this by checking if ? exists:
    $url .= (strpos($url'?') === false) ? '?' '&';
    $url .= 'someothervar=test';
    echo 
    $url
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2011
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Worked like a charm...

    I'm just having a bit of a problem with fragment identifiers. How should I format an url with a fragment identifier and a querystring?

    http://somesite.com/#message?var1=bl...eothervar=test doesn't seem to work nicely.

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See the function parse_url and some examples there.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2011
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello, read it and the examples, I'm still not sure how the url should be formed. Parsing it is only a secondary concern. I just want the browser to recognize the fragment identifier AND use the querystring with PHP.


  6. #6
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,095
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    The fragment identifier always comes last

    Code:
    http://www.example.com/?bla=bla&foo=bar#somefragment
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  7. #7
    SitePoint Zealot
    Join Date
    Jul 2011
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    It seems that the fragment identifier appears in $_GET['foo'] though.

    $_GET['foo'] == bar#somefragment

    Is there a solution to this?

  8. #8
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't get that when I tried it (fragment coming through in GET value).
    What does your link href look like in the HTML source (i.e. how is PHP rendering the URL)?
    mikehealy.com.au
    diigital.com art, design . Latest WorkSaturday Morning

  9. #9
    SitePoint Zealot wh33t's Avatar
    Join Date
    Aug 2011
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rhgiant View Post
    Worked like a charm...

    I'm just having a bit of a problem with fragment identifiers. How should I format an url with a fragment identifier and a querystring?

    http://somesite.com/#message?var1=bl...eothervar=test doesn't seem to work nicely.
    Do you mean the Octet (or is it Octothorpe?) is appearing in your URLs and you'd like to remove them?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •