morissette

Well-Known Member
May 24, 2009
119
2
66
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?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
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.