You can't.
The HTML is being parsed as an image. This throws an error and doesn't execute any client side code you might feed to it.
문제
A random website has decided to load one of my urls via the following code...
<img src="http://mysite.com/" width="1" height="1" />
I tried adding a javascript framebreaker to check and break out but that doesn't work for this. How can I make sure my site breaks out of this and is shown full browser instead of hidden? They are eating up valuable bandwidth. Thanks
Here is the framebreaker code I have already tried from within head as usual...
if(stristr($_SERVER['HTTP_REFERER'],"badsite.com") == true){
echo '<script language="Javascript">
<!--
if (top.location != self.location)
top.location.replace(self.location);
}
//-->
</script>';
}
해결책
You can't.
The HTML is being parsed as an image. This throws an error and doesn't execute any client side code you might feed to it.
다른 팁
yes you can
Easy Step-by-Step:
1- crate a folder same as:images
2- in images folder creat a folder by name of:image_folder and put your image file in "image_folder"
3-creat a .htaccess file by this content
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ -
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</IfModule>
4- creat index.php in images folder by this content:
<?
$filename = urldecode(end(explode('/',$_SERVER['REQUEST_URI'])));
$subname = current(explode('.',$filename));
$extention = end(explode('.',$filename));
switch ($extention) {
case 'gif':
$mime = 'image/gif';
break;
case 'jpg':
case 'jpeg':
case 'jpe':
$mime = 'image/jpeg';
break;
case 'png':
$mime = 'image/png';
break;
case 'ico':
$mime = 'image/x-icon';
break;
default:
header("HTTP/1.0 404 Not Found");
echo('image not finded');
exit;
break;
}
if(is_file("image_folder/".$filename)){
header("Content-type: ".$mime);
readfile("image_folder/".$filename);
}else{
header("HTTP/1.0 404 Not Found");
echo('image not finded');
}
An explanation: Now you can check referer in index.php easly
As other have said, this is not a frame break, and PHP code is not involved.
The only thing you can do is in the configuration of your server, such as adding a rule to force request to have a proper HTTP Referer.
If you use Apache, you can upload a .htaccess
on the server for this (link on a blog post I wrote long ago)
# Prevent Files image hotlinking and bandwidth stealing
RewriteEngine On
RewriteBase /blog/wp-content/uploads/
RewriteCond %{HTTP_REFERER} !^http://www.exemple.com/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|swf|flv|png)$ / [F,L]
Edit: in your case, you can do
RewriteCond %{HTTP_REFERER} ^http://nasty-site.exemple.com/.*$ [NC]
RewriteRule .* http://localhost/
That way, all traffic coming from http://nasty-site.exemple.com/ is redirected to localhost and nobody is bothered