Could you explain $_GET['image'] to me?
I mean, how do I use it? I've searched but I can't understand
The $_GET array is a super-global containing all the key-pair values that are in the URL. - For your
example.com?image=1.jpg, PHP would put one element into the
$_GET array, named
"image" with the value
"1.jpg".
For example, you could do something like this:
- <?php
-
// Assuming the following request was sent:
-
// - example.php?name=Atli&joined=2006-11-25
-
-
// Fetch the name and prepare it for output
-
$name = $_GET['name'];
-
$formatted_name = htmlentities($name);
-
-
// Fetch the joined date and re-format it.
-
$joined = $_GET['joined'];
-
$formatted_date = date("F jS, Y", strtotime($joined));
-
-
// Print stuff
-
echo "Hello, {$formatted_name}.\n";
-
echo "You joined this site on {$formatted_date}.";
-
-
// This prints:
-
/*
-
* Hello, Atli.
-
* You joined this site on November 25th, 2006.
-
*/
-
?>
See the
manual entry for more details on the
$_GET super-global.
Either way will do. I don't think it is possible to do so with HTML is it?
I mean, I know we can use php on html, but if I did that, I wouldn't be able to change the image using the url, or would I?
It doesn't really matter how you choose to display the image, changing the URL (and thus; re-submitting the request) will always re-call the PHP script and refresh the response. - PHP works on the server-side, and it doesn't really care which
type of response you send. It just executes, sends the headers and content you specify, and stops until a new request is sent.
You can choose to have PHP output a normal HTML page and include the image in a
<img> tag, or you can have PHP imitate the image itself. That is; you can have PHP "trick" the browser into thinking it is a normal image, and have it display it as such.
The HTML method is easier for you to control. It allows you to tell the browser how to display the image. The other method just sends the image and lets the browser deal with how it should be handled; whether it should be displayed or saved.
Either way, you should start by just getting PHP to fetch the image name from the URL and print it. Once you've gotten that to work, you can use either of the snippets I posted in my first post to send the actual image.
I'm sorry, but you didn't quote the whole phrase.. I sad "if you could..."
No worries. I was just explaining the situation. - We get a lot of people in here trying to get us to do their assignments for them, so they can just copy/paste them and hand them in to their bosses/teachers, so we have a strict policy against providing full-code solutions. - Not that I'm accusing you of being one of them. The same rules just have to apply to everybody :]