How to send FORM data to a perl.pl script?

Hello all.

I’m working on a small project for my company here. We have a situation where we have email hosting through Everyone.net and are trying to migrate our hosting away from them while retaining users folders/data as we IMAP copy to our inhouse server.

However we’ve ran into a problem where Everyone.net will not give us access to usernames/passwords so we can plug those into our IMAP copy applications to do the actual transfers. Instead we are left with the only solution is to create a php script that sits between the user login screen and the Everyone.net server so that when a user logs in, their information is sent to a secure location on our inhouse server in the awaiting IMAP program that will then later transfer data from Everyone.net to our inhouse server. Btw, users have been notified (we only have about 70) that we support which are clients and which have signed off agreeing to this.

So currently I have started to write a small PHP program to do this but am having problems getting it to fully work. On the main page we have an HTML FORM that that normally sends the username/pass info straight to a PERL.PL script on Everyone.net servers. I have written the PHP code thus far to instead use the form action of sending it to a local login.php page.

On the Login.php page it gets the variables from the first page via $_POST[‘variable’] ability. I then gather the username and password testing my own account that it indeed has the right information. I pass those variables into opening a cURL_init connection to the everyone.net/email/scripts/logon.pl website.

I then use CURLOPT_POSTFIELDS to pass the two fields onto the everyone.net server and execute the program and then close the curl connection. However when I run a sample login, instead of the php program taking me to the everyone.net site and logging me in, it sits on the login.php (local) page pulling the everyone.net page to me looking like it errored out logging in.

Am I doing this right? Is there ANYWAY to be able to use PHP to take HTML form information and actually log in and manipulate inside of the everyone.net email service? I know I must be missing something here… help!

Bradley

I would assume this Neowin.net thread is yours too Bradley?

Well, you might be over complicating things. :slight_smile:

Create a php script, place the following code in it and populate the $username and $password variables with valid credentials.


<?php
error_reporting(-1);
ini_set('display_errors', true);

$username = '';
$password = '';

header(
  sprintf(
    'Location: https://42007.svc.e1m.net/email/scripts/loginuser.pl?loginName=&#37;s&user_pwd=%s&login=Login',
    urlencode($username),
    urlencode($password)
  )
);
exit;

Browse to it in your browser and let me know if it logs you in OK.

Thanks for the welcome! :slight_smile:

Correct, my goal is to allow the users to login on the same webpage, nothing visually different to them. They enter their credentials, I capture those credentials and save them, but the user is forwarded right to their email account as if nothing has ever changed.

So far coding wise the only thing that is not working is that once I have their user information, I try to send that to the Everyone.net server and login and actually have the browser load up the Everyone.net email inbox page so the user can go about their ‘email business’ as usual.

Instead currently when I try to login with my user info, the page just halts and returns a copy of the Everyone.net page as if the password was not passed correctly or Everyone.net was unable to log in. Below is a copy of my PHP cURL specific code I have. This is after researching cURL for two days.

/********************************************************

  • create a new cURL resource to send to the Perl script *
    ********************************************************/

/* cURL connection for HTTPS secure */
# $ch = curl_init(‘https://42007.svc.e1m.net/email/scripts/loginuser.pl’);

/* cURL connection for HTTP non-secure */
$ch = curl_init(‘http://mail.modemnet.net/email/scripts/loginuser.pl’);
/*mail.modemnet.net is same as 42007.svc.e1m.net - domain pointer */

/*********************************************************

  • Browser-faked specific options sent to the URL by cURL *
    *********************************************************/

/* Timeout option */
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);

/* Forcing the browser type (faked) */
curl_setopt($ch, CURLOPT_USERAGENT, “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)”);

/* Forces no return output from Server */
#curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

/* Prevents error on not having SSL cert etc */
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

/* */
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

/*********************************************************

  • POST Form input fields for sending via cURL to the URL *
  • created in array to cover all input fields *
  •   						  * 
    
  • ie. <input type=“text” name=“firstName” value=“Name”> *
  • ie. $variable[‘firstName’] = ‘Name’; *
    *********************************************************/
$post_data['loginName'] = $loginName;
$post_data['user_pwd'] = $user_pwd;
# $post_data['login'] = "Login";

/*********************************************************

  • Formatting the data into a single string to send to *

  • the remote URL being posted too. *
    *********************************************************/

    foreach ($post_data as $key => $value)
    {
    $post_items = $key . ‘=’ . $value;
    }
    $post_string = implode (‘&’, $post_items);

    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

Welcome to SitePoint BTW. :smiley:

I don’t understand how you’re going to obtain the users email by ‘logging in’ to the remote site.

So, are you just wanting to provide an alternative logging version of the login form? So the user visits your form, enters their credentials, then you log them and forward the user on to the remote site as logged in?

Thanks so much for that help, it worked!! :slight_smile: You were right, I was definitely over complicating things. I just never knew all the PHP functions and syntax in this area to send / pass data to another website.

I do have one question for my own curiosity. Why is it that it works perfectly with the https://42007… address but not with the http://mail.modemnet… one? Am I correct in thinking that because the mail.modemnet… one is just a CNAME dns record forwarding to the http://42007… one that the information isn’t passed properly from one DNS over to it’s destination?

Not that it matters because the other way works perfectly but was just curious tho.

I’m definitely going to be sticking to these forums here asking for help and thoughts as I am expanding my PHP learning!

Bradley