简单的跨域php脚本

发布于 2024-10-27 23:10:36 字数 604 浏览 6 评论 0原文

我正在寻找一个简单的脚本,我可以在其中执行类似的

$.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,只是用它来构建数据库,所以我不需要包含任何装饰(不包含 get 与 post,不包含数据),只需 file_get_contents$_GET。当然我还是想对url进行编码

I'm looking for a simple script in which I can do something like this

$.getScript('fetcher.php?url=' + escape('http://www.google.com') + '&callback=console.log');

The response should be one really long line that looks like this:

console.log({responseText: '<!doctype html><html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Google</title><script>windo...'})

It shouldn't be more than 10 lines of code and there's no way it doesn't already exist.

I'm using php in XAMPP and am just using it to build a database so I don't need any frills included (no get vs post, no data included) just file_get_contents and $_GET. Of course I would still like to encoded the url

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

殊姿 2024-11-03 23:10:36

这个怎么样,更新了

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

How about this , updated

<?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>
尘世孤行 2024-11-03 23:10:36

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);
});

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);
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文