1

I need to retrieve the information from this url :

http://example.com/ajax.php?sport=soccer&language_id=vn&block_id=page_home_1_block_home_matches_1&block_name=block_home_matches&callback_params={"date": "2016-01-14", "display": "all"}&action=updateContent&params={}

With my url like this:

http://example.net/ajax.php?sport=soccer&language_id=vn&block_id=page_home_1_block_home_matches_1&block_name=block_home_matches&callback_params=%7B%22date%22%3A%20%222016-01-14%22%2C%20%22display%22%3A%20%22all%22%7D&action=updateContent&params=%7B%7D

Here is ajax.php :

<?php

$sport = $_GET["sport"];
$language_id = $_GET["language_id"];
$block_id = $_GET["block_id"];
$block_name = $_GET["block_name"];
$callback_params = $_GET["callback_params"];
$action = $_GET["action"];
$params = $_GET["params"];

$url = "http://example.com/ajax.php?sport=$sport&language_id=$language_id&block_id=$block_id&block_name=$block_name&callback_params=$callback_params&action=$action&amp;params=$params";

echo file_get_contents($url);

?>

But is return nothing, what wrong here ??

3
  • what is the result of var_dump(file_get_contents($url)); ? Commented Jan 14, 2016 at 19:42
  • @CooPer : boolean false Commented Jan 14, 2016 at 19:44
  • please check allow_url_fopen, if its true you have problem with url, you should print it and check where is the problem, for example you have &amp in your url, you must add & instead. test it step by step, without get parameter, check it with one parameter and so on. Commented Jan 14, 2016 at 19:47

1 Answer 1

1

The server might have allow_url_fopen set to Off for security (see http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen)

Try using curl to get the data instead

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
echo $data;

Separately to avoid possible issues with the data you're passing in the URL, be sure to call urlencode on each variable in case any contain special characters such as & or =. For example:

$sport = urlencode($_GET["sport"]);
Sign up to request clarification or add additional context in comments.

2 Comments

Just edited my code to this, but it return 1 : pastebin.com/RqGmemhM Here is original url : pastebin.com/Qg7RFGPw
@Tran Sorry I forgot the curl_exec line - I updated the answer - try now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.