Passing Variables threw URL

Discussion in 'PHP' started by bkflash, Oct 1, 2006.

  1. #1
    I have noticed that alot of sites pass there ID variable threw the url to the next page. does anybody know how to do this so when u click on the ID link it opens a new page with the same variables on it? an example is like this (http://www.bahb.net/index.php?file=648)

    any help here would be nice, im just trying to make a simple game site.
     
    bkflash, Oct 1, 2006 IP
  2. harsh789

    harsh789 Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #2
    <a href="http://www.bahb.net/index.php?file=<?php echo $fileid; ?>">Next Page</a>
    Code (markup):
     
    harsh789, Oct 1, 2006 IP
  3. TOM1

    TOM1 Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I think this would be the right way to go:

    http://www.bahb.net/index.php?file=<?php echo $_GET['file']; ?>
    Code (markup):
     
    TOM1, Oct 1, 2006 IP
  4. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #4
    Better process those GET variables before using them. At least at a minimun with urlencode. ;)
     
    noppid, Oct 1, 2006 IP
  5. TOM1

    TOM1 Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This is true. ;)
     
    TOM1, Oct 1, 2006 IP
  6. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #6
    
    $url = $_SERVER['PHP_SELF'].'?';
    foreach($_GET as $is => $what){
    $url .= "$is=$what&";
    }
    
    echo 'http://'.$_SERVER['SERVER_NAME'].'/'.$url;
    
    
    PHP:
     
    Barti1987, Oct 1, 2006 IP
  7. bkflash

    bkflash Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ok thanks ill try that now
     
    bkflash, Oct 1, 2006 IP
  8. the2003s

    the2003s Active Member Affiliate Manager

    Messages:
    83
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    60
    #8

    I came across this topic as I was searching for a way to encode the variables I send in an URL. noppid, can you give me an example on how to use urlencode?

    Cheers:D
     
    the2003s, Dec 3, 2006 IP
  9. CodyRo

    CodyRo Peon

    Messages:
    365
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #9
    It's pretty straight forward, check out the PHP.net explanation (they do a more in depth than I ever would)

    us3.php.net/urlencode urlencode()
    us3.php.net/manual/en/function.urldecode.php urldecode()
     
    CodyRo, Dec 3, 2006 IP
  10. the2003s

    the2003s Active Member Affiliate Manager

    Messages:
    83
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    60
    #10
    I don't know what's wrong, it just doesn't encode the variables I'm trying to send out. I have something like this: file.php?var1=256MB&var2=100. I tried creating the link like in php.net:
    <?php
    $query_string = 'var1=' . urlencode(256MB) . '&var2=' . urlencode(100);
    echo '<a href="file.php?' . htmlentities($query_string) . '">';
    ?> 
    Code (markup):
    This just makes my url look like I'm not using encription.
    Any thoughts on how to encript my urls?
     
    the2003s, Dec 5, 2006 IP
  11. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #11
    urlencode isn't actually for the encoding of string, it's more of a url formatter, it replaces spaces with %20 and such, no encoding as you know it goes on at all, just some preg_replacing, and so in the above example, urlencode isn't performing any actions at all as the words (256MB & 100) are acceptable format to be in a url.

    What exactly is it you want the link to appear as and where is it gettin vars (256MB & 100) from ?
     
    krakjoe, Dec 5, 2006 IP
  12. the2003s

    the2003s Active Member Affiliate Manager

    Messages:
    83
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    60
    #12
    I want the regular user not to be able to modify the variables I send via URL. The page from which the variables are sent is here. I then need to use the variables in several places on the destination page.
     
    the2003s, Dec 5, 2006 IP
  13. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #13
    simple way to achieve that would be base64_encode(urlencode($var)) and on the destination page, do base64_decode(urldecode($var)) on all vars in every url

    maybe someone else has a better idea.....

    If it's for a search page, you could use search ids, but inserting the form data into a `sids` table an storing what was searched in there, you could also add the search ids to session and display recent searches, or set cookies for search ids ....
     
    krakjoe, Dec 5, 2006 IP
  14. the2003s

    the2003s Active Member Affiliate Manager

    Messages:
    83
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    60
    #14
    I did this:
    <a href="mp3-player-CX112.php?cap=<?php base64_encode(urlencode('256MB'))?>&pr=<?php base64_encode(urlencode('116'))?>">Mp3 Player CX112 256MB</a>
    Code (markup):
    It doesn't seem to work.
    Any other ideas?
     
    the2003s, Dec 5, 2006 IP
  15. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #15
    I could come up with some ideas if I knew more, for instance, I don't get why you want to encode the urls if they are clicked on a page that clearly states what the url is for, seconds I don't see why you would want a static list of urls in the first place ?
     
    krakjoe, Dec 5, 2006 IP