2012-09-16 104 views
1

嗨即时尝试登录到使用PHP和Curl的网站。我遇到的问题是我要登录的网站上的输入字段的名称具有脚本认为是变量的名称。所以当我运行这个脚本时,我收到一个错误,提示未定义的变量。PHP Curl未定义的变量错误

$fields = "[email protected]&ctl00$MainContent$PasswordText=xxxx"; 

我得到的错误是:

Notice: Undefined variable: MainContent 

Notice: Undefined variable: EmailText 

Notice: Undefined variable: PasswordText 

有没有解决这个办法吗?

回答

2

是的,把字符串放在single quotes而不是双。

+0

我试过了,但我只是被重定向到登录页面 – Matt9Atkins

+1

@ Matt9Atkins:你不觉得这里绝对没有任何信息可以让任何人确定为什么会发生这种情况吗?你为什么不提到你试过了? – Jon

+0

对不起,我想我会留下一个新的问题。谢谢 – Matt9Atkins

2

如果使用“,而不是”您的变量定义的,PHP将不能解释里面的内容请参见:http://php.net/manual/en/language.types.string.php

此外,我总是用卷曲-option CURLOPT_POSTFIELDS处理后场 - 因为有了这个,我可以提交包含我的值的阵列 - 这提供了更多的美丽代码:

$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);