[英]Dead simple cross-domain php script
我正在寻找一个简单的脚本,可以在其中执行类似的操作
$.getScript('fetcher.php?url=' + escape('http://www.google.com') + '&callback=console.log');
响应应该是一条很长的线,看起来像这样:
console.log({responseText: '<!doctype html><html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Google</title><script>windo...'})
它不应超过10行代码,而且不可能不存在。
我在XAMPP中使用php,只是使用它来构建数据库,所以我不需要file_get_contents
和$_GET
包含任何装饰(没有get vs post,不包含数据)。 当然,我仍然想对网址进行编码
怎么样,更新
<?php
// fetcher.php
$url = $_GET['url'];
$callback = $_GET['callback'];
$read = file_get_contents($url);
$read = addslashes(htmlspecialchars(str_replace("\n","\\n",$read)));
?>
<script>
<?php echo $callback ?>({responseText: '<?php echo $read; ?>'});
</script>
fetcher.php
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $_GET['url']);
echo curl_exec($ch);
curl_close($ch);
?>
javascript
$.get("fetcher.php", {url: "http://www.google.com/"}, function(response) {
console.log(response);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.