View Single Post
Old August 26th, 2006, 9:08 PM   #1 (permalink)
GamingHybrid
Bow before Surpass!
Super #1
 
Joined in Sep 2004
1,544 posts
Gave thanks: 91
Thanked 49 times
How to: cPanel Form on Website.

*Although this can work for anyone, even those not reselling, this is a cool extra for Reseller's websites to help their customers*

Here is alittle tutorial on how to setup a cPanel login form on your website! NOTE: This code has the option for those logging in to make it is SSL connection or not. IF YOU DO NOT HAVE SSL ACCESS (https://) THEN PLEASE SEE STEP 3!!

----------------------------------------------------------------------------------------

Step 1: Form Code (basic)
Code:
<form action="cpanel.php" method="post">
Username: <input type="text" name="user"><br>
Password: <input type="password" name="pass"><br>
<input name="secure" type="checkbox" value="1" checked /> Secure Login?<br>
<input type="submit" name="submit" value="Login!">
</form>
This code creates a basic HTML form with values that will be used in the "cpanel.php" script. You may modfy this code in anyway, just be sure to keep the following: method="post", name="user", name="pass", name="secure", value="1", and name="submit". These are needed to retreive the right information for the script "cpanel.php" to work.

Step 2: Creating cPanel.php
The following uses PHP commands to transfer the information from the form to generate a cPanel login.
PHP Code:
<?php
// cPanel Login - NOTE: Replace website.com with your own url/domain!
if ($_POST["submit"]) {
if ((!
$_POST["user"]) || (!$_POST["pass"])) {
echo(
"Please complete all fields.");
}
else if (
$_POST["secure"] == 1){
    
header("Location: https://".$_POST["user"].":".$_POST["pass"]."@website.com:2083");} 
else {
    
header("Location: http://".$_POST["user"].":".$_POST["pass"]."@website.com:2082");}
}
?>
The first part asks if the "submit" button was clicked. then it checks to make sure both fields "user" (username) and "pass" (password" have information values, if not display the following error, "Please complete all fields.". However, if all information is found, then it proceeds with checking if the "secure" value equals "1" (aka, if the user has checked that he/she wants a SSL connection). If so, it will login using "https" and port "2083" (the secure cPanel port), if the box was unchecked, it will login using "http" and port "2082" (the unsecure cPanel standard port).

Once you've made your edits, save/close.

Step 3: What to Do if Your Account Doesn't have SSL?
If your account doesn't support SSL (usually shared servers require a one time fee for SSL, dedicated servers get it for free), then you can (and is recommended) remove the following from the form HTML code:
Code:
<br>
<input name="secure" type="checkbox" value="1" checked /> Secure Login?
And remove this from cPanel.php:
PHP Code:
else if ($_POST["secure"] == 1){
    
header("Location: https://".$_POST["user"].":".$_POST["pass"]."@website.com:2083");} 
else {
    
header("Location: http://".$_POST["user"].":".$_POST["pass"]."@website.com:2082");} 
And replace the code with the following:
PHP Code:
else {
header("Location: http://".$_POST["user"].":".$_POST["pass"]."@website.com:2082");} 
And save/close. This will remove the SSL functions fro mthe script, so that it is more efficient. However, as long as the secure field isn't checked, it would still work, this is just my suggested way on making it more clean and actually efficient. I mean, if you don't have SSL, why have the script check?

Step 4: Creating Other Service Logins
You can create logins for cPanel, but why not include this type of love for WHM, Webmail, and Broswer FTP users? You can, and with just two simple changes!

First, the most obvious change is the file name the HTML form uses. In fact, you can change itno matter what, just make sure it is the file name where the PHP coding to process the login is the same. So, for WHM logins, you can name it the basic, "WHM.php" (you can use uppercase or lowercase, of course)

Now, in the script (PHP coding), you'll need ot change the port numbers! This is so it logs in to the right service, otherwise it'll just go for cPanel, that was used in this tutorial. The following are port numbers for each service, that replaces "website.com:2083" or "website.com:2082".

Standard WHM - 2086
Secure WHM - 2087
Standard Webmail - 2095
Secure Webmail - 2096

Now, for secure FTP web-broswer login, (in the PHP coding of the script) just make the following changes that apply to your needs:

+ "https://" with "ftps://"
+ "http://" with "ftp://"
+ "website.com:20XX" with your url/domain (for both entries)

Save and close!

----------------------------------------------------------------------------------------

I hope this helps all of you that need it! Feel free to post question/support needs here. ALSO, those familiar with this type of PHP scripting, you could make it (with very minor tweaks) make multible login processings with one .php file! Otherwise, to those whom do not know this coding as well, just use the examples
__________________
GamingHybrid is offline   Reply With Quote
These users thank GamingHybrid for this great post!
azzor (March 2nd, 2007), harryb (April 16th, 2007), Patty (February 19th, 2007)