开发者

file_get_contents with url as variable

开发者 https://www.devze.com 2023-02-04 20:42 出处:网络
Can I use something like this to retrieve the page that is external with respect to the domain. <?php

Can I use something like this to retrieve the page that is external with respect to the domain.

<?php
    $q_pass =$_REQUEST['query_passed'];
    $fetcher = "http://www.abc.com/search?q=".$开发者_StackOverflow中文版q_pass;
 $homepage = file_get_contents($fetcher);
 echo $homepage;
?>

I have passed a variable and want to retrieve the result from the abc.com. Can $fetcher can be passed over to file_get_contents to retrieve the contents of the page? I am getting blank page when I hit this php page. But its again working fine if I use something like

 <?php
        $fetcher = "http://www.abc.com/search?q=query";
        $homepage = file_get_contents($fetcher);
        echo $homepage;
 ?>

What is happening here? Is there some technical explanation for this?


You should use urlencode on $q_pass. I'm guessing your passing a value with spaces in it in query_passed.

0

精彩评论

暂无评论...
验证码 换一张
取 消