How do I pass an ID in my URL on to content on my page

Discussion in 'PHP' started by arnoldus, Jan 30, 2007.

  1. #1
    I’m not a PHP programmer and would like to ask how the following can be done, which I hope would be fairly simple in PHP.

    If somebody clicks on a link to my website and the link contains a specific ID. E.g. : www.mywebsite.com/click?ID=1234

    The ID (in this case 1234) needs to be passed on to links on my webpage dynamically when my page loads. E.g. a link on my website needs to change to www.someothersite.com/click?ID=1234

    Anybody who can assist me on this?
     
    arnoldus, Jan 30, 2007 IP
  2. Dan Nilsson

    Dan Nilsson Peon

    Messages:
    72
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Such variables are stored in $_GET[], so try this:

    
    <?php
    echo '<a href="yourlink.com/click?ID='.$_GET['ID'].'">some text</a>';
    ?>
    
    PHP:
     
    Dan Nilsson, Jan 30, 2007 IP
  3. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Make sure your page has a .php extension, it does not work if pg is named .html

    You can drop that variable anywhere in the page by just pasting

    <? echo $_GET['ID'] ; ?>

    whereever you want it to go. The above commenter answered your question about building the link, but you might want to use it in other places. Just drop the above everywhere you want to see 1234

    Hope this helps
     
    ErectADirectory, Jan 31, 2007 IP
  4. LWS

    LWS Well-Known Member

    Messages:
    584
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    120
    #4
    I have a website with many links like that :)

    Basicaly the 2 posts above described well what you should do but I used a little different method so Contact me trough PM if you need more help ;)
     
    LWS, Feb 1, 2007 IP
  5. arnoldus

    arnoldus Peon

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you all!...It works like a charm.
     
    arnoldus, Feb 5, 2007 IP
  6. Lord Matt

    Lord Matt Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    When passing data about you have three ways of doing it and each has best use and not so good use.

    For example if you have a script that serves up pages index.php?page=1 then the $_GET technique works very well. You can stack several items like this index.php?page=1&chapter=7&somevar=something&book=my-book-of-stuff

    If you want to be flashy you can make the url look like this index.php/page/1/chapter/7/somevar/something/book/my-book-of-stuff but then you will need to grab all of it and use explode to create an array and then work the array to work out the values you've got (lots of work).

    The second option is to pass data as form data $_POST is then the fellow you use it works the same way as before but google can't read it. (I understand).

    The third option is good for passing things like user ID. (it's actually two methods but they get grouped as one). cookies and session. Session lasts until you close the browser and cookie lasts as long as you want it to.
     
    Lord Matt, Feb 6, 2007 IP
  7. alfredn

    alfredn Peon

    Messages:
    1,198
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If you don't want people to see the number, it might be better to use SESSIONS to keep track of the number. It will look cleaner as well; asuming you know what sessions are :) as a php coder.
     
    alfredn, Feb 6, 2007 IP