LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-16-2005, 05:28 PM   #1
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Rep: Reputation: 15
cURL script question


teh 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 :


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

Code:
<?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 (&quot;There has been an error&quot;);

//    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:

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

Code:
  'thumbSize' => '110',  //dont know if true should have quotes around it it doesnt in config file
                );
tried both ways and still got the error...

Last edited by verbatim; 05-16-2005 at 06:02 PM.
 
Old 05-16-2005, 05:55 PM   #2
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,614

Rep: Reputation: 136Reputation: 136
There is an error (or typo..) at :
PHP Code:
//    This section constructs the field/value pairs of the form
//    field1=value1&field2=value2&field3=value3
$data_string = ; // <-- need to fix that 
 
Old 05-16-2005, 07:34 PM   #3
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Original Poster
Rep: Reputation: 15
Thanks for the response.

I did as you suggested keefaz , and added the additional quote mark.
PHP Code:
$data_string ''// 
i now get the error :

Parse error: parse error, unexpected T_STRING in /var/www/html/tmpscrpts/curl2.php on line 106

Knowing the error is above line 106, i now have to start at this line:

Code:
$result = curl_exec ($curl_handle) or die (There has been an error);

and work my way up

if anyone figures out the origin of the error please let me know.

Thanks again
 
Old 05-17-2005, 05:13 AM   #4
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,614

Rep: Reputation: 136Reputation: 136
On your original post (with the smiley at line 106) :
PHP Code:
$result curl_exec ($curl_handle) or die ("There has been an error";); 
should be:
PHP Code:
$result curl_exec ($curl_handle) or die ("There has been an error"); 
Now with your new post, you said :
PHP Code:
$result curl_exec ($curl_handle) or die (There has been an error); 
That should be quoted :
PHP Code:
$result curl_exec ($curl_handle) or die ('There has been an error'); 
 
Old 05-17-2005, 12:24 PM   #5
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Original Poster
Rep: Reputation: 15
Thanks alot K,

That has got me on the right path.
 
Old 05-18-2005, 01:09 PM   #6
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Original Poster
Rep: Reputation: 15
My new dilemma:

I am trying to set up a cURL script to automatically post info to a form i have on my site. I get a 403 error when running the script.

Initially i put the curl script in my html directory so i could just type http://www.mysite.com/curl2.php and run the script. During my 1st attempt my cgi setting was


Code:
//    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


Code:
//    Path on that server to the CGI
$cgi = '/cgi-bin/';
then i got this 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?
 
Old 05-18-2005, 03:15 PM   #7
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,614

Rep: Reputation: 136Reputation: 136
You don't tell the script filename, instead you give the whole cgi-bin
directory to curl, this is wrong.

What is your cgi script filename ?
 
Old 05-18-2005, 03:23 PM   #8
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Original Poster
Rep: Reputation: 15
the name of the script is curl2.php

the script is below:
Code:
<?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 = 'www.mysite.com';

//    Path on that server to the CGI
$cgi = '/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;
 
Old 05-18-2005, 04:50 PM   #9
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,614

Rep: Reputation: 136Reputation: 136
No, this one is the script which connect to the cgi script. This is not the cgi script
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Curl command backpackingbiker Ubuntu 1 06-21-2005 04:16 PM
PHP/cURL housemusic42 Linux - Networking 0 10-07-2004 02:45 PM
Curl Conflict christer Linux - Software 0 10-13-2003 11:38 AM
php and curl Risen Linux - Software 0 09-02-2003 03:41 PM
how to use curl to download? gexiaofei Linux - Software 6 07-26-2003 05:01 PM


All times are GMT -5. The time now is 04:24 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration