Reputation: 3276
Hi im attempting to login to a website using PHP and Curl. The problem I am having is that the names of the input fields on the website I want to log into have names that the script thinks is a variable. So when I run the script I get an error saying undefined variables.
$fields = "[email protected]&ctl00$MainContent$PasswordText=xxxx";
The errors I am getting are:
Notice: Undefined variable: MainContent
Notice: Undefined variable: EmailText
Notice: Undefined variable: PasswordText
Is there any way around this?
Upvotes: 1
Views: 2892
Reputation: 41
If you use ' instead of " of your variable-definition, php will not interpret the content inside. See: http://php.net/manual/en/language.types.string.php
Additionally, i always use the curl-option CURLOPT_POSTFIELDS for handling post-fields - because with this i can submit an array containing my values - that gives more beautiful code:
$curlhandle = curl_init();
$post_values = array(
'ctl00$MainContent$EmailText' => '[email protected]'
'ctl00$MainContent$PasswordText' => 'xxxx'
);
curl_setopt($curlhandle, CURLOPT_POST, true);
curl_setopt($curlhandle, CURLOPT_POSTFIELDS, $post_values);
Upvotes: 2
Reputation: 41597
Use single quotes:
$fields = '[email protected]&ctl00$MainContent$PasswordText=xxxx';
Upvotes: 3