Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

php code to login to webmail

Discussion in 'cPanel Developers' started by morissette, Jan 28, 2014.

  1. morissette

    morissette Well-Known Member

    Joined:
    May 24, 2009
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    66
    Location:
    Austin, TX
    cPanel Access Level:
    Root Administrator
    Code:
                    
                    $port = "2095";
                    $url = "http://$server:$port/login/";
                    $fields = array('user' => $user, 'pass' => $pass);
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL, $url);
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                    curl_setopt($ch, CURLOPT_HEADER, 1);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                    curl_setopt($ch, CURLOPT_POST, 1);
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
                    $result = curl_exec($ch);
                    $pattern = '/Set-Cookie:(.*?)\n/';
                    if ( preg_match($pattern, $result, $matches ) ) {
                        $cookie = $matches[1];
                    }
                    if ( preg_match('/Location:\s+(\S+)/', $result, $matches ) ) {
                        $end = $matches[1];
                    }
                    $url = "http://$server:$port" . $end;
                    curl_close($ch);
    
    This returns a url with the cpsession however I am stuck on trying to figure out how to make the session stick. Any advice?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,303
    Likes Received:
    1,847
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello :)

    I believe the following document may be of help:

    Secure Remote Logins

    However, if not, could you elaborate a little more on the specific action you are attempting?

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. morissette

    morissette Well-Known Member

    Joined:
    May 24, 2009
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    66
    Location:
    Austin, TX
    cPanel Access Level:
    Root Administrator
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice