1

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?

3 Answers 3

3

Use single quotes:

$fields = '[email protected]&ctl00$MainContent$PasswordText=xxxx';
Sign up to request clarification or add additional context in comments.

Comments

2

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

3 Comments

I tried that but I just get redirected to the login page instead
@Matt9Atkins: Don't you think that there is absolutely no information here to let anyone determine why that happens? Why didn't you mention that you tried it anyway?
sorry, I guess I will leave that for a new question. Thanks
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.