Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to use a form to post data to an external URL, and I'm completely stumped by this problem.

The exact code I'm using is:

<form name="login" action="https://www.example.com/" method="post">
<input id="username" maxlength="50" name="username" type="text" value="username" onfocus="if(this.value == 'username') { this.value = ''; }"><br />
<input id="password" maxlength="50" name="password" type="password" value="password" onfocus="if(this.value == 'password') { this.value = ''; }"><br />
<input id="clientsubmit" type="submit" name="login" value="login"><br />
</form>

This code works perfectly in a blank html page, and logs me right in to the website I'm trying to log into. When I try to use the exact same code with a WordPress page, the page seems to refresh, and that's all I get.

I'd appreciate any help you guys might be able to give. I'm totally stumped on this one and I can only assume that it's a WordPress peculiarity.

share|improve this question
I ended up just embedding an iframe of a simple HTML document with just the login form into my WordPress page, and setting target="_blank" on the form element. Never thought I'd use an iframe again. – pstjean Jan 18 '12 at 18:31
Did you try disabling JavaScript? Some javascript might be manipulating form's action, but that's a wild guess. – Zlatev Nov 11 '12 at 10:21
Are you using IE? Did you try Firefox? Are you getting a XSS (Cross Site Scripting) error? I have heard that IE sometimes gives strange XSS behavior. – Magenta Cuda Feb 23 at 20:40

closed as too localized by toscho Mar 5 at 23:42

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

You need to use curl to remotly login

Try this:

$myurl = 'myurl';
$details = array(
        'username'=> 'username',
        'password'=> 'password',
    'remember_me' => '1'
    ); 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$myurl);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$details);
$page = curl_exec($ch);
echo $page;

//close connection
curl_close($ch);

Source: http://stackoverflow.com/questions/6126566/remote-login-with-curl-php

Please Note:
You should check the fields value and match with
variables that are now called username & password..

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.