www.webdeveloper.com
Results 1 to 11 of 11

Thread: [RESOLVED] Whats .php?id= mean??

  1. #1
    Join Date
    Mar 2007
    Posts
    63

    resolved [RESOLVED] Whats .php?id= mean??

    A lot of sites have "page.php" but it also has a ?id= or just a ? after it. After the ? theres usually a bunch of numbers so it ends up looking like page.php?id=23569 or something similar. Can someone explain to me what's happening there?

  2. #2
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    What follows the ? is called a query string. Those values can be read in either by a server side scripting language or by Javascript in order to be processed and update the page.

    With page.php?id=something the page.php script would be able to access the $_GET['id'] field to determine that it has a value of 'something' and then use that value to control what appears on the page.

  3. #3
    Join Date
    Mar 2007
    Posts
    63
    Okay. So if I was using this function...

    function openmedia(id)
    {
    window.open('/movies/openmedia.php?id=' + id,'Media','width=370,height=270,resizable=no,copyhistory=no,toolbar=no,directories=no');
    }
    How could I go about making openmedia.php display what id is?

  4. #4
    Join Date
    Mar 2007
    Posts
    63
    I figured it out. I used this ...

    <?php
    echo $_REQUEST['id']
    ?>

  5. #5
    Join Date
    Mar 2007
    Posts
    63
    I realise this is a triple post but is it possible to display just a section of what is outputted by $_GET['id']. Like if my page was
    page.php?id=testsun.jpg
    I can use the code in my previous to output the whole id (testsun.jpg) but I only need the 'sun.jpg'. Is it possible to just obtain one part of the id?

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,616
    Sure it's possible, depending on whether you can specify the precise rule(s) that determines what part of the value is to be used. For instance, if you want to skip the first 4 characters of whatever the value is:
    PHP Code:
    $value substr($_GET['id'], 4); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    You would need to determine what the rule is for what part of the value you want before being able to work out the best way of extracting that part probably either by using a substr or regular expression.

    It is always preferable security-wise to reference $_GET when reading the querystring because with $_REQUEST you don't know whether you have obtained the value from a GET, a POST, or a COOKIE.

  8. #8
    Join Date
    Mar 2007
    Posts
    63
    Thanks. Extracting it by using the starting position and the length wont work though because in my case the length changes. Is there any way to split the querystring by something like a ',' or '/' ?

  9. #9
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,616
    You could use explode(), though if the string truly represents two separate data items, why not send it as two variable/value pairs?
    Code:
    page.php?id=test&image=sun.jpg
    Then there would be two $_GET values:
    PHP Code:
    echo $_GET['id'];    // outputs "test"
    echo $_GET['image']; // outputs "sun.jpg" 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  10. #10
    Join Date
    Mar 2007
    Posts
    63
    Would this function do that..

    function openmedia(id,image)
    {
    window.open('/movies/openmedia.php?id=' + id + image,'Media','width=370,height=270,resizable=no,copyhistory=no,toolbar=no,directories=no');
    }
    ..I realise it's javascript though but would it still be writing to seperate data items

  11. #11
    Join Date
    Mar 2007
    Posts
    63
    Screw it, explode works awsome. Thanks guys

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles