The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Webmail login script redirect on failure

Discussion in 'cPanel Developers' started by boy143878, Mar 30, 2008.

  1. boy143878

    boy143878 Member

    Joined:
    Mar 29, 2008
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    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>
     
  2. LiNUxG0d

    LiNUxG0d Well-Known Member

    Joined:
    Jun 25, 2003
    Messages:
    206
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    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,
     
  3. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
  4. LiNUxG0d

    LiNUxG0d Well-Known Member

    Joined:
    Jun 25, 2003
    Messages:
    206
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    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,
     
Loading...

Share This Page