I don't understand how this works?...

Discussion in 'PHP' started by loopline, Aug 6, 2007.

  1. #1
    I know of a site that uses php links to pass on some info to a php script. Here is an example link:
    http://www.free-icons.co.uk/index.php?mode=getcode&dir=Movies/&image=myspace-icons-animals142.gif
    This is the part that is important from the link:
    ?mode=getcode&dir=Movies/&image=myspace-icons-animals142.gif
    or you can just click the link and look in the address bar.

    I would like to do something like this, but not with icons. I am new to php, but I think I can make it work if I can understand how this link passes on the info in it. I am trying to create a dynamic page, similar to the one above, where I can put info up without having to make each and every page. Just a template and have php place the code and image. So here is what I don't understand:

    I gather that the dir=movies and image=myspace-icons-animals142.gif are going to be passed on to the script. What I don't know is how to create a php string that will capture the image=myspace-icons-animals142.gif info from the link and then take the info that is in the image=myspace-icons-animals142.gif and create a variable that is equal to myspace-icons-animals142.gif? (so that in the php page $image=myspace-icons-animals142.gif from the link) I don't need the dir part, but I do need the image part. What is mode=getcode? I think I understand the ? mark that separates the link from the variables in the link, but if anyone wants to elaborate on it that would be nice too.

    I am not sure if if I stated that correctly, but feel free to ask any questions to help better understand. Thank you in advance for your help.

    MAtt
     
    loopline, Aug 6, 2007 IP
  2. Greg Carnegie

    Greg Carnegie Peon

    Messages:
    385
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I am not sure what you are asking about, so i will try to break everything into pices.

    ? is a begining of query string, after '?' you can add variables in form key=value seperated by '&'.

    I suppose creating such string is not a problem for you it can be done even in plain HTML.

    To get this variables you need to use $_GET array. In case which you described you will have such variables.
    $_GET['dir'] = 'Movies/';
    $_GET['mode'] = 'getcode';
    $_GET['image] = 'myspace-icons-animals142.gif';
     
    Greg Carnegie, Aug 6, 2007 IP
    loopline likes this.
  3. loopline

    loopline Well-Known Member

    Messages:
    738
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Excellent! That is exactly what I needed. It may seem basic, but I just needed a push over the hump. Thanks!

    MAtt
     
    loopline, Aug 7, 2007 IP