Jump to content

cURL


Recommended Posts

Hi there,

 

Can any of you nice people see what's wrong with this snippet of PHP code using cURL?  I'm really not that familiar with the library so I'm really just amending existing scripts.

 

My thoughts arethat the credentials are not being encoded into the URL (maybe?).

 

Thanks in advance,

 

Paul.

 

<?php

 

/* Constants */

$bcUser = 'yyyyyyy';

$bcPass = 'xxxxxxxx';

$bcURL = 'http://service.bulletinconnect.net/api/1/sms/in';

$bcRatecode = FALSE;

 

 

/* Send the request */

RequestIncoming($bcUser, $bcPass);

 

/*RequestIncoming Function */

function RequestIncoming($user, $pass) {

global $bcURL;

 

print 'user: ' . $user . '<p>';

print 'pass: ' . $pass . '<p>';

 

$data = "userId=".urlencode($user) . "&password=".urlencode($pass);

 

print 'data: ' . $data;

 

$cUrl = curl_init();

curl_setopt($cUrl, CURLOPT_URL, $bcURL);

curl_setopt($cUrl, CURLOPT_HEADER, 'Content-type: application/x-www-form-urlencoded');

curl_setopt($cUrl, CURLOPT_GET, 1);

curl_setopt($cUrl, CURLOPT_GETFIELDS, $data);

curl_setopt($cUrl, CURLOPT_TIMEOUT, 30);

curl_exec($cUrl);

 

$code = curl_getinfo($cUrl, CURLINFO_HTTP_CODE);

       

curl_close($cUrl);

 

return $code;

print 'code: ' . $code;

}

Link to comment
Share on other sites

There's no "GETFIELDS" .. just alter the url like this:

 

$get_url = $bcURL . '?' . $data;

 

Then get rid of the HEADER, GET and GETFIELDS lines.  As GET is the default action, there is no need to specify that curl should use it.

Link to comment
Share on other sites

Hi,

 

Thanks for helping me out, I'm absolutely stuck with this one!

 

I'm confused about where the line $get_url = $bcURL . '?' . $data; should go though.  Should it be like this?  I guess not because I'm still getting the same error message.

 

Thanks,

Paul.

 

/* Constants */

$bcUser = 'xxxxx';

$bcPass = 'yyyyy';

$bcURL = 'http://service.bulletinconnect.net/api/1/sms/in';

$bcRatecode = FALSE;

 

 

/* Send the request */

RequestIncoming($bcUser, $bcPass);

 

/*RequestIncoming Function */

function RequestIncoming($user, $pass) {

global $bcURL;

 

print 'user: ' . $user . '<p>';

print 'pass: ' . $pass . '<p>';

 

$data = "userId=".urlencode($user) . "&password=".urlencode($pass);

 

print 'data: ' . $data;

$get_url = $bcURL . '?' . $data;

$cUrl = curl_init();

 

curl_setopt($cUrl, CURLOPT_URL, $bcURL);

curl_setopt($cUrl, CURLOPT_TIMEOUT, 30);

curl_exec($cUrl);

 

$code = curl_getinfo($cUrl, CURLINFO_HTTP_CODE);

       

curl_close($cUrl);

 

return $code;

print 'code: ' . $code;

}

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.