Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    New Zealand

    Authenticating against cpanel's usernames and passwords

    Here's a little PHP function I wrote which others might find useful one day.

    I had a need (or will soon at least) to allow somebody to login to a PHP system I had written, but I wanted them to use thier cpanel username and password to do so.

    I thought about it for a while, and did some searching but I couldn't come up with anything. Until I realised that I was thinking about it the wrong way - why not just send the supplied username and password along to the cpanel and see if it works, if it does then they are authenticated, if not, then they're not

            function auth_cpanel($username, $password, $host = 'localhost')
                    $ch = curl_init("http://{$host}:2082/");
                    curl_setopt($ch, CURLOPT_USERPWD, "{$username}:{$password}");
                    curl_setopt($ch, CURLOPT_NOBODY,  TRUE);
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
                    if(($x = curl_getinfo($ch, CURLINFO_HTTP_CODE)) != 200)
                            if($x != 401) // If some other error happened than auth failure
                                trigger_error("Authencation server failure.", E_USER_ERROR);
                            // No Auth
                            return FALSE;
                            // Authorized
                            return TRUE;

  2. #2
    Ohh. Excellent, I might find some use for this. Thanks for your code!

  3. #3
    Join Date
    Jun 2004
    Bay Area -USA
    I found this very helpful and saved me time. Thank you very much!!
    <<< Please see Forum Guidelines for signature setup. >>>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts