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?
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.
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?
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
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.
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 '/' ?
"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
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
Bookmarks