This tutorial will allow you to login to
several different ports that are used for cPanel. Then it will get the
correct protocol and redirect the user to a URL assuming the login
information is correct.
cPanel, WHM, Webmail login script
The following code will allow you to login to several different ports that are used for cPanel.
<form action="cpanelLogin.php" method="POST">
<?php
if(($_GET['failed'] == "1") or ($error == 1)){
echo '<font color="#FF0000">Your login attempt failed!</font><br />';
}
?>
Domain: <input type="text" name="domain" value="" size="20" /><br />
Username: <input type="text" name="username" value="" size="20" /><br />
Password: <input type="password" name="pass" value="" size="20" /><br />
<?php
echo '<input type="hidden" name="failurl" value="http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?failed=1">';
?>
Options: <select name="port">
<option value="2082">cPanel </option>
<option value="2083">Secure cPanel </option>
<option value="2086">WHM</option>
<option value="2087">Secure WHM</option>
<option value="2095">Webmail</option>
<option value="2096">Secure Webmail</option>
</select><br />
<input type="submit" value="Login" />
</form>
Above we created a very basic form to allow the users to login with.
You can spice this up to match your site, you just have to make sure
that the field names – the name=” some text ” – remains the same.
If you only want to allow cPanel logins you can change the
<select name=”port”> to <input type=”hidden” name=”port”
value=”2082″>. This allows you to only show the domain, username and
password fields.
One thing you will have to make sure you change is the action on the
<form> so that it points to the file you will be saving on the
next page of this article.
Now the brains of this script.
<?php
if($_POST['domain'] && $_POST['username'] && $_POST['pass'] && !($_GET['failed'] == "1")) {
$port = $_POST['port']; switch($port) {
case '2082': case '2086': case '2095': $protocol = 'http://';
break;
case '2083': case '2087': case '2096': $protocol = 'https://';
break;
}
$redirectlocation = $protocol.$_POST['domain'].':'.$port.'/login/?user='.$_POST['username'].'&pass='.$_POST['pass'].'&failurl='.$_POST['failurl'];
header ("Location: ".$redirectlocation); } else {
$error = 1;
header ("Location: ".$_POST['failurl']); }
?>
I commented this out so you can see what is actually going on and should be fairly easy.
You can save this as anything, I choose cpanelLogin.php and then post to this file in the form you created on the previous page.
|