Click to See Complete Forum and Search --> : [RESOLVED] Whats .php?id= mean??
r_sole
03-16-2007, 10:19 PM
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?
felgall
03-16-2007, 10:53 PM
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.
r_sole
03-16-2007, 11:49 PM
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?
r_sole
03-17-2007, 12:12 AM
I figured it out. I used this ...
<?php
echo $_REQUEST['id']
?>
r_sole
03-17-2007, 12:47 AM
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?
NogDog
03-17-2007, 01:34 AM
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:
$value = substr($_GET['id'], 4);
felgall
03-17-2007, 01:37 AM
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.
r_sole
03-17-2007, 01:52 AM
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 '/' ?
NogDog
03-17-2007, 01:58 AM
You could use explode (http://www.php.net/explode)(), though if the string truly represents two separate data items, why not send it as two variable/value pairs?
page.php?id=test&image=sun.jpg
Then there would be two $_GET values:
echo $_GET['id']; // outputs "test"
echo $_GET['image']; // outputs "sun.jpg"
r_sole
03-17-2007, 02:04 AM
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
r_sole
03-17-2007, 02:30 AM
Screw it, explode works awsome. Thanks guys :)