The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 18, 2019, 07:35:33 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Google images [not] cloaking  (Read 4632 times)
m0nkeymafia
Expert
****
Offline Offline

Posts: 240


Check it!


View Profile
« on: March 10, 2008, 06:44:28 AM »

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:
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
Code:
<?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()
?>

Logged

I am Tyler Durden
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #1 on: March 10, 2008, 07:40:43 AM »

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?
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
m0nkeymafia
Expert
****
Offline Offline

Posts: 240


Check it!


View Profile
« Reply #2 on: March 10, 2008, 08:05:12 AM »

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?
Logged

I am Tyler Durden
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #3 on: March 10, 2008, 09:26:07 AM »

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.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #4 on: March 10, 2008, 09:34:03 AM »

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

hai
m0nkeymafia
Expert
****
Offline Offline

Posts: 240


Check it!


View Profile
« Reply #5 on: March 10, 2008, 09:36:00 AM »

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 magnetic locks on them near you?
Well we do... and when you go over a magnetic 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 magnetic locks... OWWW!!!
Logged

I am Tyler Durden
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!