m0nkeymafia

Wordup!

Right here is what im tryin to do:
A lot of my images on one of my sites get looked at through google images, most people click the link at the top to go directly to the image though, meaning I don't have a chance at getting a backlink... So what I want to do is use mod rewrite to check if an image is being loaded, then check if google images et al is the referrer, if so display the picture and a simple "heres how to get your image" bit of text... However I seem to have run into a small problem, it's not working and I'm not entirely sure why... Any thoughts guys?

htaccess code:
### Help get links back from google images ###
RewriteCond %{REQUEST_URI} (.*).(png)$ [NC]
RewriteCond %{HTTP_REFERER} images.google.(.*)$ [NC]
RewriteRule (.*) /picviewer.

php

 ?imgpath=$1 [PT]


PHP

  File picviewer.

php

 

<?

php

 
// Put in this array every substring that identifies the URL of an image search:
$hr = array("images.google", "images.search.yahoo.com", "search.live.com/images/");

// Assign the requested URL to $imgpath
$imgpath = '/'.$_GET["imgpath"];

// Loop the array
foreach($hr as $imgreferrer)
{
$found = strpos($_SERVER["HTTP_REFERER"], $imgreferrer); // Check the actual referer against the given ones
if ($found !== false)
{
// if an Image Search URL is detected in the HTTP REFERER value, show landing page:
header("Content-type: text/html");

$linkcode  = '<a href="http://xxx.com" alt="xxx title="xxx">';
$linkcode .= '<img src="http://xxx.com'.$imgpath.'" alt="xxx" title="xxx" />';
$linkcode .= '</a>';
$linkcode = htmlentities($linkcode);
?>

<center>
<h1>Put this image on your site with the following code:</h1>
<? echo $linkcode; ?>
<br /><br />
<img src="<?

php

  echo $imgpath; ?>" alt="" />
</center>

<?

php

 
die(); // Don't go further in the Loop
}
}
//Commented out for now as this file should only be called upon a images.google.* referrer
//header("Content-type: image/png"); // MAKE SURE that the content type matches your image's one here
//echo file_get_contents($imgpath); // MAKE SURE you can open URLs in

PHP

  with file_get_contents()
?>

nutballs

it might be because the browser is expecting an image (mime type) and you are sending back HTML. if thats the case, youare screwed since there is no way around that, except possibly to do a redirect. THough I doubt an image can redirect, i never tried it.

have you tried just printing something simple like 'aaaaa' to the screen, from your picviewer.

php

  when its hit via an image load?

m0nkeymafia

I got it working, then it stopped so I figured that "it working" was a fluke.
Perhaps I should specify html/text mime so the browser won't get confused?

nutballs

yea try that but I have a feeling it wont work.

if the url is something.com/picture.jpg the browser will force the mimetype of jpeg for security reasons. there used to be an attack vector using jpgs to do evil things by changing the mimetype and running malicious code. I think all modern browser prevent this by locking the mime to the file extension for known web image types.

i could be completely wrong of course since I am working from a memory of about 5 years ago. so take it with a grain of salt.

vsloathe

How about a bunch of grains of salt, a shot of tequila, and then a lemon?

m0nkeymafia

quote author=vsloathe link=topic=823.msg5663#msg5663 date=1205166843

How about a bunch of grains of salt, a shot of tequila, and then a lemon?


Argh... weekend flashback!

Do you guys have the trolleys with ma

gnet

 ic locks on them near you?
Well we do... and when you go over a ma

gnet

 ic strip in the road the wheels lock... after a more than a few shots me and a friend were Trolley Surfing in a shopping center car park until we hit the ma

gnet

 ic locks... OWWW!!!


Perkiset's Place Home   Politics @ Perkiset's