0

I have a PayPal button which upon checkout completion redirects the user back to the homepage but in the background opens another php page which does a couple of things including updating some databases etc. However in it it I'd also like to perform a rest API request.

http://your-server/rest/createUser?username=testuser&password=testpassword

Here is the URL I need to fire and I'm not too bothered about reading the contents of this to be honest, it respond an XML file saying status OK or error messages but I don't need this... All I want to do is access the URL. This works from a browser, but when I try to use

$apicall = file_get_contents("http://your-server/rest/createUser?username=testuser&password=testpassword"); 

It doesn't work... Any thought ?

1 Answer 1

1

For file_get_contents() to work correctly any special characters have to be encoded.

$url = 'http://your-server....'; $encodedUrl = urlencode($url); $apicall = file_get_contents($encodedUrl); 

The other thing to check is that allow_url_fopen php.ini setting is set to true. (It is by default).

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

3 Comments

nope doesn't work. It's a weird one, the URL works from a browser, but not when using file_get_contents... Should I be able to echo the $apicall or display it somehow to check it's working?
If you use a hosting provider I would ask them about it.
Re logging try error_log('fgc:' . print_r($apicall, true));. Output goes to error log. which maybe /var/log/apache2/error_log but that depends on your web service and config.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.