I am trying to send username and password parameters to a url using curl, and I want to retrieve them. I send the parameters to a page, like the following:
&
you can find the username and password in the global $_SERVER
array
$_SERVER : array
(
....
'PHP_AUTH_USER' => 'the_username'
'PHP_AUTH_PW' => 'the_password'
)
Some of the parameters, like CURLOPT_USERAGENT
are send in the HTTP headers and can be retrieved using special globals like $_SERVER['HTTP_USER_AGENT']
(see http://www.php.net/manual/de/reserved.variables.server.php).
Others, like CURLOPT_SSL_VERIFYPEER
are only local to CURL and don't get send to the server.
to send parameters to a web page you can use 1 of two methods GET or POST
GET is where the parameters are appended to the name of the resource you are getting
e.g $url = "http://localhost/sample.php?name=" . urlencode( $value )
the other choice is via a POST. post is sent to the server as a page of information to do this with curl you create a post with
curl_setopt($ch, CURLOPT_POSTFIELDS, 'name=' . urlencode( $value ) . '&name2=' . urlencode( $value2 ));
If on the other hand you are talking about Headers, then you can access them through the $_SERVER['headername']
array.
DC
By default, cURL issues an HTTP GET request. In this case, you'd have to append the parameters to the URL you're calling:
$curl = curl_init('http://localhost/sample.php?foo=bar&baz=zoid');
In sample.php
, $_GET['bar']
and $_GET['baz']
would be available respectively. If it's a POST request, you want to issue, you'll need to set the parameters via curl_setopt
:
$curl = curl_init('http://localhost/sample.php');
curl_setopt($curl, CURLOPT_POSTFIELDS, 'foo=bar&baz=zoid');