2

I tried to sent an SMS using an API with file_get_contents() in PHP.

Eg.

file_get_contents("http://testsmssite/SMS.php?username=xx&password=ccc&message=MESSAGE&numbers=1111111111&sender=11111"); 

In local machine it works well.

If i Put it in to server[SERVER A] its not working.If i change the code ie. file_get_contents("http://google.com"); it works fine in both server and local.

if i put this page ie

file_get_contents("http://testsmssite/SMS.php?username=xx&password=ccc&message=MESSAGE&numbers=1111111111&sender=11111"); 

in to another server[SERVER B] it works fine.

If it is any problem with my [SERVER A] then how it open google?

Can any one help me to fix this issue ?

3
  • not sure, but perhaps your hosting server is configured to prevent requests to certain group of sites. Commented Jul 27, 2011 at 5:52
  • 2
    http get request... so exposing usernames and passwords isn't an issue? Commented Jul 27, 2011 at 5:53
  • Are you getting any errors when on Server A? Commented Jul 27, 2011 at 5:55

4 Answers 4

3

Instead of using file_get_contents, try using curl. See what you get back as a response and check curl_error. There are many possible reasons that could cause the request to fail.

Sign up to request clarification or add additional context in comments.

Comments

2

Check your error log. If file_get_contents fails, it tells you the reason why in the PHP error log if you log warnings and notices.

In a related question, Why doesn't file_get_contents work?, some have created a collaborative wiki answer that deals with how to trouble-shoot file_get_contents in detail. Maybe the infos and comments help you as well.

Comments

0

Can you check if allow_url_fopen is true/enabled, for more http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen? It could be a reason. And yes, Curl could be a better option.

Comments

0

Check if http://testsmssite is accessible from Server A (try pinging it). Maybe you'll have to add it to /etc/hosts. Or maybe you have to change settings on testsmssite. IMO it's network issue, not related to PHP itself (since on server A PHP is able to load data from http://google.com)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.