【问题标题】:PHP and Curl not Returning Output with VariablePHP 和 Curl 不返回带变量的输出
【发布时间】:2015-05-30 20:55:35
【问题描述】:

这是我的 index.php 文件...

<?php

    // Defining the basic cURL function
    function curl($url) {
        $ch = curl_init();  // Initialising cURL
        curl_setopt($ch, CURLOPT_URL, $url);    // Setting cURL's URL option with the $url variable passed into the function
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Setting cURL's option to return the webpage data
        $data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
        curl_close($ch);    // Closing cURL
        return $data;   // Returning the data from the function
    }
	$url1 = $_GET['link'];
    $response = curl($url1);
    $response = str_replace("./views","http://movietube.pm/views",$response);
	$response = str_replace("./lib","http://movietube.pm/lib",$response);
	$response = str_replace("./assets","http://movietube.pm/assets",$response);
	echo $response;
	?>
// Defining the basic cURL function
function curl($url) {
    $ch = curl_init();  // Initialising cURL
    curl_setopt($ch, CURLOPT_URL, $url);    // Setting cURL's URL option with the $url variable passed into the function
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Setting cURL's option to return the webpage data
    $data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
    curl_close($ch);    // Closing cURL
    return $data;   // Returning the data from the function
}
$url1 = $_GET['link'];
$response = curl($url1);
$response = str_replace("./views","http://movietube.pm/views",$response);
$response = str_replace("./lib","http://movietube.pm/lib",$response);
$response = str_replace("./assets","http://movietube.pm/assets",$response);
echo $response;
?>

基本上,我想要它做的是接受输入 www.example.com?link=(链接) 并在执行 php 后返回页面的 HTML... 在输出中,它会正确加载页面,但不会放入电视节目内容,例如视频播放器、链接或剧集导演...

它的作用...

http://muchmovies.uphero.com/?link=http://www.tvstreaming.cc/watch.php?v=TGmi0OPy0Cc

我想让它做什么......

http://www.tvstreaming.cc/watch.php?v=TGmi0OPy0Cc

感谢任何帮助!

【问题讨论】:

  • 你在 curl_exec 之后忘记检查 curl 错误

标签: php html curl


【解决方案1】:

也许你的 php 变量 $_GET['link'] 有问题,因为你放了这个链接:

http://muchmovies.uphero.com/?link=http://www.tvstreaming.cc/watch.php?v=TGmi0OPy0Cc

请注意,您的查询字符串将是这样的: ?link=http://www.tvstreaming.cc/watch.php?v=TGmi0OPy0Cc

此查询字符串必须是编码的,而您没有对其进行编码,因此,变量 $_GET['link'] 将没有您需要执行 curl 的值。

我向您推荐 2 个选项:

  1. 编码网址参数
  2. 或者,使用 base64 编码传递 url,然后在您的 服务器使用基本解码

请告诉我这是否是解决方案。

【讨论】:

  • 感谢您的回复。我认为这也可能是语法错误或其他原因,但如果您查看页面底部,则有针对特定电影的 facebook cmets。我假设这意味着链接正在到达网站,并且告诉它获取该视频。不幸的是,缺少的 3 个部分对我来说是最重要的,即视频、视频链接和剧集指南。
  • 会不会是服务器端的东西阻止了我获取那些 html 标签?在网页的调试器中,整个视频部分就消失了。
  • 不,真正的问题是主要内容是使用 $.ajax POST 请求加载的,而不仅仅是调用您认为的 url。用 firebug 打开 firefox 或用 Chrome inspector 打开 Google Chrome,去 url 看看 XHR requests,然后你就会知道使用了哪个 url。
  • 好的,谢谢。仅使用 PHP 是否仍然可以做到这一点?
  • 是的,因为使用 curl 您可以执行各种请求,在这种情况下 POST 没有任何问题。但是,如果你想删除电影数据,我建议你使用像 IMDB 这样的公共 API。
猜你喜欢
  • 2019-06-17
  • 1970-01-01
  • 1970-01-01
  • 2013-10-14
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多