Webmail login script redirect on failure

boy143878

Member
Mar 29, 2008
7
0
51
Hello,

I have the followig code below that will login into the domain's webmail. The code is on a custom login page domain.com/maillogin.php. The code works fine. The only problem is if a user enters a wrong user/password, they get redirected to the default webmail login page, http://domain.com:2095/login/. I would like to have it go to the domain.com/maillogin.php page. I've been searching around for a solution with no luck thus far. Any help would be great.

Lance

<?php

#Webmail
$protocol = 'http';
$port = 2095;


<html>
<b>cPanel Login</b><br>
<?php
if ($_GET['failed'] == "1") {
echo "Your login attempt failed!";
}
echo "<form action=\"" . $protocol . "://";
echo $_SERVER['HTTP_HOST'] . ":" . $port . "/login/\" ";
echo "method=POST>";
?>
User: <input type=text name=user><br>
Pass: <input type=password name=pass><br>
<?php
echo "<input type=hidden name=failurl value=\"http://" ;
echo $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
echo "?failed=1\">";
?>
<input type=submit value=Login>
</form>
</html>
 

LiNUxG0d

Well-Known Member
Jun 25, 2003
206
1
168
Gatineau, Quebec, Canada
Hey there Lance,

If you're submitting data to http://www.domain.com:2095/login/ well, cPanel will take control of what returns will occur. Short of re-coding this thing to submit in the background (AJAX-style) there isn't a way of getting what you want. Technically, if you edited the cPanel files you could tell it where to go, but I don't think you should be doing that for many reasons. ;)

I - personally - would make a script that curls the URL with the username and password, checks it to see if it will log in (by regex may I suggest) and then if successful, can log you in automagically by sending the user to the same URL via header() redirect.

I replied to someone with some code today, which is up your alley:

http://forums.cpanel.net/showthread.php?t=77540

The problem is the submission to port 2095/login/. That page is what will control the return.

Let me know if I've been of any assistance.

Warmest regards,
 

LiNUxG0d

Well-Known Member
Jun 25, 2003
206
1
168
Gatineau, Quebec, Canada
Hi,

Since the failurl is - obviously - a parameter cPanel supports (sorry; didn't know), try typing it in concretely instead of abstractly. Try actually typing the URL your failurl should go to, and not the PHP version of it.

PHP:
<?php
echo "<input type=hidden name=failurl value=\"http://" ;
echo $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
echo "?failed=1\">";
?>

Becomes:

<?php
print "<input type='hidden' name='failurl' value='http://www.domain.com/URI?failed=1'>";
?>
By doing this, you can rule out if it's a problem with the actual PHP output. Just to see/debug. :)

Just a thought,