Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Canada, Ontario, Mississauga
    Posts
    312
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php url variables

    Hello everyone,

    right now the url is http://localhost?var1=99&var2=88
    If I want to add var3=77 to http://localhost?var1=99&var2=88
    What should or can I do?

    when I use $_SERVER['PHP_SELF'] it only create link to http://localhost but without ?var1=99&var2=88
    I want to add var3=77 to the end of the address, anyone know the best way to do this??

    thank you so much

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not quite sure what you want and where you wana use it, but you can always use a concatanation like:

    PHP Code:
    print $_SERVER["PHP_SELF"] . "?var1=99?var2=88?var3=77"

  • #3
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If I understood the question:

    Get the vars first:

    $var1 = $_GET['var1'];
    $var2 = $_GET['var2'];
    $var3 = '77';

    You say $_SERVER['PHP_SELF'] is giving you only http://localhost, so there you are:

    $url = "".$_SERVER['PHP_SELF']."?var1=".$var1."&var2=".$;var2."&var3=".$var3."";

    Basically what ConfusedOfLife says. (we were writing at the same time)

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Won't $_SERVER['QUERY_STRING'] work?

  • #5
    Regular Coder
    Join Date
    Apr 2003
    Location
    Canada, Ontario, Mississauga
    Posts
    312
    Thanks
    0
    Thanked 0 Times in 0 Posts

    No, this is wa I want

    the initial address is http://localhost?var1=99&var2=88

    now, I want to add var3=77 to the end

    maybe later, I will add var4=##

    then var5=##

    you know... keep on going.. is there a way to grab the host name + all the vars that's in the url???

    thank you all for your quick reply..

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts

    Re: No, this is wa I want

    Originally posted by weronpc
    the initial address is http://localhost?var1=99&var2=88

    now, I want to add var3=77 to the end

    maybe later, I will add var4=##

    then var5=##

    you know... keep on going.. is there a way to grab the host name + all the vars that's in the url???

    thank you all for your quick reply..
    Well you can grab the URL using a server variable. You can grab the variables in the URL using the $_GET[] array. You don't have to know their names. You can just loop through the array like you would any other and generate a link using that and concatenate on the next variable and value.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:

    $link 
    $_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING']; 
    is that what you want?

  • #8
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    As many times as I've looked through the server variables listed in the manual I had never seen query_string before now. Nice.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #9
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    its on this page

    http://www.php.net/manual/en/reserve...riables.server


    you have to be careful tho, becuase in a script i was writing, i kept getting errors when there was no query string. it seems that the $_SERVER['QUERY_STRING'] is not even set if there is no query string, rather than it just being an empty string.

  • #10
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    lol that's what I said a few posts back

  • #11
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Originally posted by Nightfire
    lol that's what I said a few posts back
    It's okay. I missed yours the first time because it was so small. Very nice.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #12
    Regular Coder
    Join Date
    Apr 2003
    Location
    Canada, Ontario, Mississauga
    Posts
    312
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thank you all

    You guys are good, thank you...

    Sorry Nightfire, I missed your reply...

    you guys forgot "?"

    $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']

  • #13
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeh sorry nightfire, i missed that too

  • #14
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    lol no problem, atleast the problem's solved


  •  

    Posting Permissions

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