Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Member
    Join Date
    Apr 2008
    Posts
    26

    Default webmail login using cURL

    Hi,

    I am attempting to use the following code to login to webmail using cURL and PHP. It is able to login (I am able to get it to display the logged in content), but it doesn't do the redirect to the webmail page, instead just spitting back the html itself it seems.

    PHP Code:
    <?php
    error_reporting
    (E_ALL);

    // get user name and password from $_POST
    $cpanelemail $_POST['emailaddress'];
    $cpanelemailpass $_POST['pass'];

    if (
    $cpanelemail != '' || $cpanelemailpass != '') {
    // build cPanel webmail URL
    $post2 = array();
    $post2['user'] = $cpanelemail;
    $post2['pass'] = $cpanelemailpass;
    $post2['goto_uri'] = '/';
    $post['login_theme'] = 'cpanel';

    //print_r($post2);
    $url 'https://xxx.site.com:2096/login/';
    //$cookie="cpanel_cookie.txt";

    $ch curl_init();
    curl_setopt($chCURLOPT_POSTFIELDS$post2);
    curl_setopt($chCURLOPT_COOKIEJAR'Ocookie.txt');
    curl_setopt($chCURLOPT_URL$url);
    curl_setopt($chCURLOPT_HEADER1);
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
    curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
    curl_setopt($chCURLOPT_SSL_VERIFYHOST0);

    //$content = curl_exec($ch);
    curl_exec($ch);
    //curl_close($ch);

    //print $content;
    }
    else {
    // empty variables / no login details provided
    print header("Location: cpanel_login.php?failed=2");
    }

    //exit;
    ?>

  2. #2
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    You may want to take a look at LogMeIn.pm - http://forums.cpanel.net/437949-post5.html

  3. #3
    cPanel Staff cPanelMatt's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default

    On your server are you using cookie auth or HTTP auth?

    Most cPanel servers (and by default) use HTTP auth (which is the pop up box that asks for user name and pass) in that case, you can use fairly generic code to login to the webmail page like what's described in the following article Using cURL and libcurl with PHP no need to go to /login/ at all.

    After running this, when printing the output of curl_exec does it show "Login Attempt Failed" at all?
    Matt Dees
    Integration Developer
    cPanel, Inc.
    cPanel Integration Blog

  4. #4
    Member
    Join Date
    Apr 2008
    Posts
    26

    Default

    You guys are both awesome. I was inspired by David's suggestion of LogMeIn.pm to do something similar in PHP (using my current code, getting the session name and then passing it to a new Location: header).

    The problem was that cURL wasn't handling relative paths properly (completely ignoring them) and was simply returning the logged in page instead.

    Thanks guys!

Similar Threads & Tags
Similar threads

  1. Webmail login page and customize webmail server installation
    By patelbhavin8008 in forum E-mail Discussions
    Replies: 2
    Last Post: 05-25-2011, 05:22 AM
  2. Slow login to webmail and sending mail through webmail ?
    By Hack in forum E-mail Discussions
    Replies: 7
    Last Post: 05-18-2011, 03:35 PM
  3. Replies: 0
    Last Post: 10-10-2010, 02:55 AM
  4. Webmail login through CURL
    By boy143878 in forum cPanel Developers
    Replies: 7
    Last Post: 06-18-2008, 04:02 PM
  5. Showing mail quota in webmail or webmail login?
    By internetfab in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 08-28-2007, 11:02 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube