21,891
社区成员
发帖
与我相关
我的任务
分享
<input type="text" id=goo />
<input type="button" id=but />
var tmp=document.getElementById('but');
tmp.onclick=function(){
var obj=document.getElementById('goo');
window.open('http://www.google.cn/search?hl=zh-CN&q='+obj.value);
}
<?php
/**
* @desc 支持referer的url访问
* @author shadu###foxmail.com
* @param string $url 要访问的页面
* @param string $ref 从哪个网站访问的
*/
function get_UrlContent($url,$ref) {
$ch = curl_init ( $url );
curl_setopt ( $ch, CURLOPT_TIMEOUT, 10 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" );
curl_setopt ( $ch, CURLOPT_REFERER, $ref);
$content = curl_exec ( $ch );
curl_close ( $ch );
return $content;
}
/**
* @desc 我猜lz是想在http://127.0.0.1/search.html嵌入Google广告代码,
* 所以这个$ref最好还是设置下,否则广告挣的钱就不是你的了:)
*/
$ref = 'http://127.0.0.1/search.html';
$url = "http://googleads.g.doubleclick.net/pagead/sdo?client=dist-aff-pub-8581564299250417&output=html"
."&dt=1246961633609&format=js_sdo&h=35&w=500&correlator=1246961633609&same_win=2&logo=left&rl_pos=right"
."&cts_mode=rs&num_cts=2&box_h=26&box_w=215&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_his=7"
."&u_java=true&u_nplug=0&u_nmime=0&frm=0&lmt=1246961632"
."&url=$ref&dtd=0";
echo get_UrlContent($url,$ref);
?>
<?
function get_url($url)
{
$url = str_replace(" ", "%20", $url);
$TheURL_header = substr($url, 0, 7);
if($TheURL_header == "http://")
{
$pos = strpos($url, "/", 7);
if($pos)
{
$host = substr($url, 7, $pos - 7);
}
else
{
$host = substr($url, 7);
}
}
else
{
return false;
}
$TheURL_footer = substr($url, strlen("http://".$host."/"));
$http_header = "";
$http_header .= "GET /".$TheURL_footer." HTTP/1.1\r\n";
$http_header .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; Alexa Toolbar)\r\n";
$http_header .= "Host: ".$host."\r\n";
$http_header .= "Connection: close\r\n";
$http_header .= "Cache-Control: no-cache\r\n";
$http_header .= "\r\n";
$data = "";
$bytes = 0;
$fp = @fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp)
{
return false;
}
fwrite($fp, $http_header);
while(!feof($fp))
{
$tmp_stream = fgets($fp, 1280);
$stream_header = substr($tmp_stream, 0, 9);
$stream_header = strtolower($stream_header);
if($stream_header == "location:")
{
//---- 转走了 ----
$remote_url = substr($tmp_stream, 9);
$remote_url = trim($remote_url);
$the_url_header = substr($remote_url, 0, 7);
if($the_url_header != "http://")
{
if(substr($remote_url, 0, 1) == "/")
{
$remote_url = substr($remote_url, 1);
$remote_url = "http://".$host.$remote_url;
}
else
{
$pos_url = strrpos($url, "/");
$remote_url = substr($url, 0, $pos_url)."/".$remote_url;
}
}
fclose($fp);
return get_url($remote_url);
}
$stream_header = substr($tmp_stream, 0, 15);
$stream_header = strtolower($stream_header);
if($tmp_stream == "\r\n")
{
//---- 头部信息结束 ----
break;
}
}
while(!feof($fp))
{
$tmp_stream = fgets($fp, 1280);
$data .= $tmp_stream;
}
fclose($fp);
return $data;
}
echo get_url("http://googleads.g.doubleclick.net/pagead/sdo?client=dist-aff-pub-8581564299250417&output=html&dt=1246961633609&format=js_sdo&h=35&w=500&correlator=1246961633609&same_win=2&logo=left&rl_pos=right&cts_mode=rs&num_cts=2&box_h=26&box_w=215&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_his=7&u_java=true&u_nplug=0&u_nmime=0&frm=0&lmt=1246961632&url=http://127.0.0.1/search.html&dtd=0");
$url = 'http://googleads.g.doubleclick.net/pagead/sdo?client=dist-aff-pub-8581564299250417&output=html&dt=1246961633609&format=js_sdo&h=35&w=500&correlator=1246961633609&same_win=2&logo=left&rl_pos=right&cts_mode=rs&num_cts=2&box_h=26&box_w=215&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_his=7&u_java=true&u_nplug=0&u_nmime=0&frm=0&lmt=1246961632&url=http://127.0.0.1/search.html&dtd=0';
$opts = array(
'http'=>array(
'method'=>'GET',
'header'=>'User-Agent: Mozilla'
)
);
echo $html = file_get_contents($url,false,stream_context_create($opts));