Portal Home > Knowledgebase > Articles Database > cPanel webmail login using cURL


cPanel webmail login using cURL




Posted by larwilliams, 06-15-2009, 01:55 PM
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.

Posted by BMG_Servers, 06-16-2009, 12:39 AM
Since you have CURLOPT_HEADER set, what headers are you getting back when you make the request? Depending on the type of redirect, you may need to handle the redirect manually if curl isn't taking care of it, but I think analyzing what you are getting back would be a good start since you have CURLOPT_FOLLOWLOCATION set and the redirect is not working. Also, just a little thing I noticed...you might want to check your logs on those requests. Curl has an additional option called CURLOPT_POST that forces the request to be a POST request(as opposed to a GET request). While not directly related to your issue, it's very possible that the data is being added as a query string in a GET request, in which case your password may be ending up in the server logs(along with whatever other POST data is sent). Just a heads up and something to keep an eye on from a security aspect. And lastly, maybe a typo on where you're setting the theme of $post vs $post2.

Posted by larwilliams, 06-16-2009, 01:02 AM
I just noticed the typo as well. I doubt that has much to do with it, as cPanel has a default theme set and "login_theme" only serves to override it. $post2 is an array built for feeding cURL the post data and it seems to work fine as well. I have already ensured that all form data is named correctly (looked at the cPanel webmail login page and emulated it field for field, including hidden ones) and sent to $_POST. The weird thing being that cURL is being told to follow redirects, but isn't (even though there is one in the headers I get back) I get a "HTTP/1.1 301" (forgive the formatting if it's wrong) status back and a "Location: /webmail/x3/?login=1" header (which is where it should redirect to). Perhaps the relative path is messing up cURL? That is the only thing I can think of.

Posted by BMG_Servers, 06-16-2009, 01:49 AM
Curl should handle the 301 redirect, especially since CURLOPT_FOLLOWLOCATION is set. The redirect looks OK and while the Location header is supposed to be absolute(at least in an RFC I saw), Curl should have no problems handling it(unless it's a really old version of Curl). Is safe mode on or is open_basedir set? Maybe take a look at the post at http://php.net/manual/ro/function.curl-setopt.php#71313 and see if it applies to you or helps any?



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
PHP Problem (Views: 585)
eAccelerator tweak (Views: 603)
Server load issues (Views: 580)