Forum Moderators: coopster

Message Too Old, No Replies

cURL script question

whats this error?

         

verb

12:00 am on May 17, 2005 (gmt 0)

10+ Year Member



the script below gives me the following error:

Parse error: parse error, unexpected '=' in /var/www/html/tmpscrpts/curl2.php on line 88

line 88 is :

$data_string .= $key . '=' . $value;


<?php
/*
There are two fundamental ways for PHP to send data to another
CGI via the POST-method: CURL and fopen.

Where CURL is the easier of the two, fopen is more commonly available.

Check the output of phpinfo() to see whether CURL is available on your system.


*/

/*
This method uses CURL to contact the server.

*/

// Either 'http' or 'https'. 'https' is only an option if OpenSSH
// is available on your system. Check phpinfo() to see whether
// HTTPS is available.
$HTTP_method = 'http';

// IP-resolvable FQDN of the server
$hostname = 'hostname.mysite.com';

// Path on that server to the CGI
$cgi = '/var/www/cgi-bin';

// Array of data. The foreach loop below is going to construct a field/data
// string like the one you see in the URL of a GET-method CGI.
$my_data = array (

'dbType' => 'mysql',
'dbHost' => 'localhost',
'dbUser' => 'memb',
'dbPass' => 'okay',
'dbName' => 'memb_com_-_sy',
'dbPrefix' => 'mel_',
'dbPersistent' => 'false',
'syPath' => '/var/www/html/userz/mel/',
'uploadPath' => 'uploads/',
'syHTTPPath' => '/userz/mel/',
'templatePath' => 'templates/',
'uploadHTTPPath' => 'uploads/',
'baseURL' => 'http://www.mysite.com/userz/mel/',
'autodetect_baseURL' => 'false', //dont know if true should have quotes around it it doesnt in config file
'indexFile' => 'index.php',
'user' => 'mel',
'pass' => 'thanks',
'realname' => 'mel', //should get from signup p h p
'email' => 'michael@hotmail.com', //should get from signup p h p
'want_mail' => 'true', //dont know if true should have quotes around it it doesnt in config file
'allowSubscriptions' => 'true', //dont know if true should have quotes around it it doesnt in config file
'blogTitle' => 'John Does personal blog',
'blogDescription' => 'My little place on the web...',
'lang' => '', //dont know if true should have quotes around it it doesnt in config file
'lang_content_negotiation' => 'false', //dont know if true should have quotes around it it doesnt in config file
'fetchLimit' => '15', //dont know if true should have quotes around it it doesnt in config file
'useGzip' => 'true', //dont know if true should have quotes around it it doesnt in config file
'wysiwyg' => 'false', //dont know if true should have quotes around it it doesnt in config file
'XHTML11' => 'false', //dont know if true should have quotes around it it doesnt in config file
'enablePopup' => 'false', //dont know if true should have quotes around it it doesnt in config file
'embed' => 'false',
'top_as_links' => 'false', //dont know if true should have quotes around it it doesnt in config file
'blockReferer' => ',',
'rewrite' => 'array()', //dont know if true should have quotes around it it doesnt in config file
'serverOffsetHours' => '0', //dont know if true should have quotes around it it doesnt in config file
'showFutureEntries' => 'false', //dont know if true should have quotes around it it doesnt in config file
'magick' => 'false', //dont know if true should have quotes around it it doesnt in config file
'convert' => '/usr/local/bin/convert',
'thumbSuffix' => 'syThumb',
'thumbSize' => '110' //dont know if true should have quotes around it it doesnt in config file
);

// This section constructs the field/value pairs of the form
// field1=value1&field2=value2&field3=value3
$data_string = ';
$add_ampersand = FALSE;
foreach ($my_data as $key => $value)
{
if ($add_ampersand)
{
$data_string .= '&';
}
$data_string .= $key . '=' . $value;
$add_ampersand = TRUE;
}

// Get a CURL handle
$curl_handle = curl_init ();

// Tell CURL the URL of the CGI
curl_setopt ($curl_handle, CURLOPT_URL, $HTTP_method . '://' . $hostname . $cgi);

// This section sets various options. See http://www.php.net/manual/en/function.curl-setopt.php
// for more details
curl_setopt ($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl_handle, CURLOPT_POST, 1);
curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data_string);

// Perform the POST and get the data returned by the server.
$result = curl_exec ($curl_handle) or die ("There has been an error";

// Close the CURL handle
curl_close ($curl_handle);

// Process the return
print $result;

any ideas why?

I'm also not sure if i should have a coma behind the last data field:

 'thumbSize' => '110' //dont know if true should have quotes around it it doesnt in config file
);


or

 'thumbSize' => '110', //dont know if true should have quotes around it it doesnt in config file
);


tried both ways and still got the error...

StupidScript

9:37 pm on May 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the code you posted is copy-and-paste, here's your error, on line 80:

$data_string = ';

Should be:

$data_string = '';

The error showed up on line 88 because the first apostrophe on line 88 closes the

$data_string
assignment, and is immediately followed by the
=
sign it's complaining about.

verb

10:25 pm on May 17, 2005 (gmt 0)

10+ Year Member



thanks SS

StupidScript

10:38 pm on May 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You betcha, verb. Welcome aboard! ;)

verb

5:39 pm on May 18, 2005 (gmt 0)

10+ Year Member



My new problem:

My initial thoughtwas to put the curl script in my html directory so i could just type [mysite.com...] and run the script.

However, I get a 403 forbidden error: You don't have permission to access /cgi-bin/ on this server using that method.

when i attempt to access the php file via my cgi-bin:
[mysite.com...] i get a 500 internal service error.

is it not possible for me to run the curl script from my web browser?

And what have i not configured [or mis-configured] giving me the above errors?
This is the 1st script i have put on the system though that refers to the cgi-bin. I dont know if i need to make a index.html or .htaccess file inside the cgi-bin folder in order for this script to work correctly?

Initially i put the curl script in my html directory so i could just type [mysite.com...] and run the script. During my 1st attempt my cgi setting was


// Path on that server to the CGI
$cgi = 'http://www.mysite.com/';

that of course didnt work. I recieved the error:
Couldn't resolve host 'www.mysite.comhttp:'

2nd attempt was


// Path on that server to the CGI
$cgi = '/cgi-bin/';

then i get the error:

403 forbidden

Forbidden
You don't have permission to access /cgi-bin/ on this server.

my cgi path is /var/www/cgi-bin/

what am i doing wrong?

StupidScript

6:26 pm on May 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're on a shared server. It is possible that your hosting company gives you access to a cgi-bin directory, but undoubtedly it is not the primary /var/www/cgi-bin directory. More than likely you have restrictions on what scripts in your personal cgi-bin can do, too.

It might be in some directory like:

http://www.mysite.com/userz/mel/cgi

the path for which is likely something like:

/var/www/userz/mel/cgi-bin

Check with your hosting company about your cgi-bin access and restrictions.