How to add id variable on url to inside a webpage? On the fly?

Discussion in 'PHP' started by misohoni, Apr 9, 2012.

  1. #1
    For example, I've seen web pages which have:
    index.php?id=dffdfd

    The dffdfd variable is then automatically added on the webpage itself...how did they do that, especially whatever id is entered in the url it's generated on the webpage when it's refreshed...
     
    Solved! View solution.
    misohoni, Apr 9, 2012 IP
  2. SocksEscort

    SocksEscort Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The basic idea is to set the window.location.hash property to a value that contains whatever state information you need, then either use the window.onhashchange event, or for older browsers that don't support onhashchange (IE < 8, Firefox < 3.6), periodically check to see if the hash has changed (using setInterval for example) and update the page. You will also need to check the hash value on page load to set up the initial content.
     
    SocksEscort, Apr 9, 2012 IP
  3. misohoni

    misohoni Notable Member

    Messages:
    1,717
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    200
    #3
    misohoni, Apr 15, 2012 IP
  4. Arttu

    Arttu Member

    Messages:
    139
    Likes Received:
    2
    Best Answers:
    8
    Trophy Points:
    40
    #4
    Is this what you mean?
    
    <?php
    $id = $_GET['id'];
    
    echo $id;
    ?>
    
    Code (markup):
     
    Arttu, Apr 16, 2012 IP
  5. misohoni

    misohoni Notable Member

    Messages:
    1,717
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    200
    #5
    I think that's along the same line but how can I duplicate a typed in $id in the url, which is then displayed on the actual page itself?
     
    misohoni, Apr 16, 2012 IP
  6. #6
    Thats how its done, as long as its valid, take the example
    showthread.php?t=2447750

    you could write in showthread.php
    
    if (isset($_GET['t'])) {
       $t = $_GET['t'];
       echo $t;
    }
    
    PHP:
    which would then print the topic number if it exist.
    type in another topic number which exist, and it will print it after page loaded. If it doesnt exist, it would not print it.

    To generate that on the fly while your typing, javascript / jquery has to be used. Though iam not sure if its good idea regarrding security
     
    Basti, Apr 16, 2012 IP
    misohoni likes this.
  7. misohoni

    misohoni Notable Member

    Messages:
    1,717
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    200
    #7
    Cheers, yep I'm looking for it on the fly really though ;(
     
    misohoni, Apr 16, 2012 IP
  8. Basti

    Basti Active Member

    Messages:
    625
    Likes Received:
    6
    Best Answers:
    3
    Trophy Points:
    90
    #8
    Could you tell us for what purpose?

    Your original post doesnt seem to make sense to me. If one type something in the url, what is supposed to happen beside a hit on "enter" on your keyboard? which make him go to that page. And then the javascript var value would be lost unless its cached.
    And then, its simplier to just use the php method, its crossbrowser and bulletproof
     
    Basti, Apr 16, 2012 IP