PHP Curl未定义变量错误

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 = "ctl00$MainContent$EmailText=xxxx@xxxx.com&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?

Yes, put the string inside single quotes instead of double.

Use single quotes:

$fields = 'ctl00$MainContent$EmailText=xxxx@xxxx.com&ctl00$MainContent$PasswordText=xxxx';

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' => 'xxxx@xxxx.com'
    'ctl00$MainContent$PasswordText' => 'xxxx'
);
curl_setopt($curlhandle, CURLOPT_POST, true);
curl_setopt($curlhandle, CURLOPT_POSTFIELDS, $post_values);