File_get_contents with url as variable

Can I use something like this to get a page that is external to the domain.

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

I passed a variable and want to get the result from abc.com. Can $ fetcher be passed to get_contents to retrieve page content? I get a blank page when I get to this php page. But its working fine again if I use something like

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

What's going on here? Is there any technical explanation for this?

+4
source share
1 answer

You must use urlencode on $ q_pass. I assume that you pass the value with spaces in it to query_passed.

+4
source

Source: https://habr.com/ru/post/1335287/


All Articles