Jump to content

[SOLVED] cURL remote server, no browser PLEASE HELP


candeman

Recommended Posts

Hello everyone I'm new here and desperately looking for an answer. I use cURL to Post to to a remote server (mediatemple) from m localhost server. This works fine as long as I open the page in a browser, however I'm using an sms server that executes php script in the background. when an sms is received the local php script runs and I want to use use cURL to execute script on a remote host. Again it works if I test the local php script in a browser, but it doesnt work when executed with the sms server.

 

Is there some cURL pararmeter I can use, that may prevent the script from not being executed if its not loaded from a browser, or is there any way I can see the result of the php page that is loaded in the background, by mean of a log or something?

 

Thanks for your time

 

Hank from the Bahamas

 

 

Link to comment
Share on other sites

$phoneNumber = '4045551111';

$message = 'This message was generated by curl and php';

$curlPost = 'pNUMBER='  . urlencode($phoneNumber) . '&MESSAGE=' . urlencode($message) . '&SUBMIT=Send';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://www.example.com/sendSMS.php');

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);

$data = curl_exec();

curl_close($ch);

 

This is not my exact code, but I'm at work and cant access it but this is essentially it, again its works and if I try it in a browser it works but executed from within server no

Link to comment
Share on other sites

Also because I got this to work using a browser..... I used header("www.mysite.php?".var=url_encode('example')) and was able to redirect the local page to the remote page with the POST vars I wanted, is it possible to do this or something equivalent without using a browser? Basically I need to post vars to a remote server without a browser

Link to comment
Share on other sites

Erm... if I understand his question properly, he's already using cURL. The clue's in the topic title and the code he's posted.

 

I'm just wondering how the server is running the script? Is it a cron job? How is it physically running the code?

Link to comment
Share on other sites

Well, cURL can impersonate a browser if thats helpful....

curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");

 

But what exactly doesn't work? Try adding something like this to the top of your script so that you can see any errors when its run on your sms server.

 

error_reporting(E_ERROR);
ini_set('error_log', '/some/writable/path/errorlog');

 

 

Link to comment
Share on other sites

Erm... if I understand his question properly, he's already using cURL. The clue's in the topic title and the code he's posted.

 

Yes, i know - i've not gone completely insane, i've just absolutely no idea what happened here. When i posted, my reply was the first - and the question being asked was rather different.

 

I came back later and checked the topic only to find that lots of people had posted before me and the question had changed. All very bizarre.

Link to comment
Share on other sites

Actually, come to think of it your reply did seem familiar to a reply in another topic I read very recently. It made more sense in that topic than this one. I can't remember what it was called though.

 

I'll have a root around and perhaps this mystery can be solved.

Link to comment
Share on other sites

Actually, come to think of it your reply did seem familiar to a reply in another topic I read very recently. It made more sense in that topic than this one. I can't remember what it was called though.

 

I'll have a root around and perhaps this mystery can be solved.

 

That topic IS this topic. If i view my last posts, the title of the topic is different, but it links to this one. I guess SMF just had a funny 5 minutes.

Link to comment
Share on other sites

Thank you for your time, I found the answer to my problem. The server software I use has a php plugin that triggers when sms are received it also has a 'HTTP Client' plugin, Apparently the request I was trying to make doest work with that php plugin, not sure why as it does all other php related functions connection to database etc. Using the http Client directed to the same php file EVERYTHING works. Sure you smart people understand why that is, but I'm satisfied with it just working!, Thanks and sorry for your time!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.