Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

403 forbidden error with cURL script. no access to cgi-bin???

Status
Not open for further replies.

verbatim1

Programmer
Apr 18, 2005
58
US
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 and run the script. During my 1st attempt my cgi setting was

Code:
//    Path on that server to the CGI
$cgi = '[URL unfurl="true"]http://www.mysite.com/';[/URL]

that of course didnt work. I recieved the error:
Couldn't resolve host '
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/
what am i doing wrong?

The php cURL 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 = '[URL unfurl="true"]www.mysite.com';[/URL]

//    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/[URL unfurl="true"]www/html/userz/mel/',[/URL]
  'uploadPath' => 'uploads/',
  'syHTTPPath' => '/userz/mel/',
  'templatePath' => 'templates/',
  'uploadHTTPPath' => 'uploads/',
  'baseURL' => '[URL unfurl="true"]http://www.mysite.com/userz/mel/',[/URL]
  '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' => 'michaelldemery@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 [URL unfurl="true"]http://www.php.net/manual/en/function.curl-setopt.php[/URL]
//    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;
 
when looking for the httpd.conf file on web server I found this directory
a. ”etc/httpd/conf” &
b. “/var/log/httpd “ [access logs] – no httpd.conf file in in though
c. /usr/lib/httpd/modules [libphp.so file]

my site is hosted by
i looked through all folders and saw no httpd.conf file.

I assume from that that they dont give me access to it.

I initially had the file set to 644, then changed it to 755...
 
wishdiak,
should i put this .htaccess file in the cgi-bin folder, the root directory, or another location?
Verb
 
when i typed in th whole path

i go t a 404 error,

The requested URL /var/ was not found on this server.

i read on another site that i have booklmarked on another computer that when putting the cgi path, '/var/ should be left out.

i tried with and without the file name as such: /var/
&

/var/
neitgher worked...
 
verbatim1,

Path names should include the path to the directory that the file is in, not the file name itself.

If this particular script wants the '/var/ portion of the path omitted, then specifying the path as '/cgi-bin' would be correct.

What are the permissions on /var/ And you'd most likely want to put a .htaccess file in /var/ to allow CGI execution.

Wishdiak
A+, Network+, Security+, MCSA: Security 2003
 
It seems to me that you are posting to the cgi-bin directory and not specifying a script name. You are forbidden to browse the script directory, hence the 403.

Try providing the script name in the url as in or whatever...

Jeb Beasley

\0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top