Solved

Cannot read CPanel login page (401 Access Denied Still Working)

Posted on 2008-10-07
7
1,555 Views
Last Modified: 2012-05-08
The following code attempts to read the CPanel login page on my own server. The code fails even though the login page can be read manually in any browser. The failure message is as follows:

Warning: file_get_contents(http://64.131.68.211:2082/): failed to open stream: HTTP request failed! HTTP/1.1 401 Access Denied Still Working in C:\Web\TestHTTPS-EE.php on line 5

I am using PHP 5.1.6 and openssl is enabled. I am using Apache 2.2.3 on Windows running on my local computer as localhost.

The problem also occurs if I move this PHP file to a remote server. It also occurs if I add the username and password to the URL.

Note that other websites, even secure ones, can be read without a problem by similar coding. For example, $url="https://65.200.16.78/"; works.

I have searched the Web but cannot find a solution.

<?php
// Read and display CPanel login page
$url="http://64.131.68.211:2082/"; // Fails ("401 Access Denied Still Working")
$C=file_get_contents($url);
echo $C;
?>

Open in new window

0
Comment
Question by:dspector
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 8

Accepted Solution

by:
RWJDCom earned 300 total points
ID: 22659549
I have had similar problems when I was trying to read the cPanal login page for something I was writing and what I found was that using file_get_contents was not the way to go and using cURL worked a alot better.  

cPanel also has an API you can use if you are just trying to run commands.  :)

Again, try using cURL instead of file_get_contents.   You can get the syntax from http://www.php.net, just do a search for cURL.

I hope this helps.
0
 
LVL 1

Author Comment

by:dspector
ID: 22660462
Thanks, but I don't want to use cURL, a separate library, since there is nothing that cURL can do that PHP proper should not be able to do. I want a genuine solution in PHP if it is possible. There should be one possible, since I believe that PHP proper can accomplish any kind of Internet connection that a browser can.

Since this bug affects other people, a solution will also benefit others. If this is a bug in file_get_contents or wrappers, that would be good to know, so I can report it to The PHP Group.

Perhaps someone else out there can find a way to make this work without using cURL?

Additional hint: what makes CPanel different from other sites is that it frequently uses a self-signed (untrusted) security certificate, as it does in this case. Browsers complain, too, the first time they try to read the page. Then they succeed when the user clicks a button or two.

0
 
LVL 1

Author Comment

by:dspector
ID: 22672371
I've implemented the solution using cURL, and it works fine if you set the parameters CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER to false, causing security certificates to be ignored. Of course, the application can query the user before doing this, so at least the lower security is made obvious.

But surely a page with a self-signed or untrusted certificate can be opened with fsockopen? Surely someone out there can figure out how to do this without requiring the entire cURL Library?

Someone? Anyone?
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 1

Author Comment

by:dspector
ID: 22711706
This question has been open for awhile, but there is as yet no good answer.

If no one knows the answer, I will delete or close this question so it doesn't remain open. EE doesn't like questions that are open for too long.

David
0
 
LVL 8

Expert Comment

by:RWJDCom
ID: 22713746
Unfortunately I don't think your going to be able to accomplish what you want using just standard PHP.  That's why I suggested that you use cURL to do it because most providers have cURL compiled into PHP or if not they can surely add it for you.

I wish I could help you more.

-Jeff
0
 
LVL 1

Author Comment

by:dspector
ID: 22717454
I can't imagine what cURL could do that PHP cannot do, since I believe that PHP gives full access to socket control.

Jeff, since you were the only person who even bothered answering, I'll give you the "answer", but like many questions I've asked here and elsewhere I'm not really satisfied with the answer. Our computer environment is great when we are doing something ordinary, but when we try to do something unique its limitations get revealed pretty fast.

David
0
 
LVL 1

Author Closing Comment

by:dspector
ID: 31656949
Thanks for taking the time to help!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question