Reputation: 7482
Trying to display an image only for Android users, but I don't want to use any redirection for it.
So far I have this, but it uses header() which redirects.
if (strstr($_SERVER['HTTP_USER_AGENT'],"Android")) {
header("Location: app.png");
}
Upvotes: 0
Views: 97
Reputation: 4439
It depends on what you want to do. If you want to display the image inside an HTML document, why not use this kind of code?
if (strstr($_SERVER['HTTP_USER_AGENT'],"Android")) {
echo '<img src="app.png"/>';
}
Upvotes: 0
Reputation: 12618
You can just output the image in your page, using readfile. Make sure to send the correct headers as well.
For example:
if(strstr($_SERVER['HTTP_USER_AGENT',"Android"))
{
header('content-type: application/png'); //Let the client know its a png.
readfile('app.png');
}
This way any request made to your page using Android will result in the raw image being returned. If you want to 'force' the client to download the image send the content-disposition
header as well.
Upvotes: 3