View Full Version : Login script
Reg Web
July 22nd, 2005, 05:31
I have just made a login script, but how can I allow for multiple usernames/passwords? All I got at the moment is:
<form>
<p>USER NAME :
<input type="text" name="text2">
</p>
<p>PASSWORD :
<input type="password" name="text1">
<input type="button" value="Login" name="Submit" onclick=javascript:validate(text2.value,"1039atc",text1.value,"*****") >
</p>
</form>
<script language = "javascript">
/*
Script by Anubhav Misra (anubhav_misra@hotmail.com)
Submitted to JavaScript Kit (http://javascriptkit.com)
For this and 400+ free scripts, visit http://javascriptkit.com
*/
function validate(text1,text2,text3,text4)
{
if (text1==text2 && text3==text4)
load('http://members.1039online.org/frontpage.php');
else
{
load('http://members.1039online.org/failedlogin.php');
}
}
function load(url)
{
location.href=url;
}
</script>
dnplace
July 22nd, 2005, 09:18
i can help pm me for that
Canuckkev
July 22nd, 2005, 11:55
Please, please don't actually use this code for a login system...please.
Use some sort of server side application, or .htaccess. Not JavaScript, which someone can easily view the code in plain text.
overulehost
July 22nd, 2005, 13:18
yeah.. true.
try hotscripts.com and search for some sort of php login script
R4g1ng
July 23rd, 2005, 10:13
Its really easy to make a login script with php.
<?php
if($action=="login") {
$user = $_POST['user'];
$pass = $_POST['pass'];
if(($user == "user1" && $pass == "pass1") || ($user == "user2" && $pass == "pass2")) {
header(Location:frontpage.php);
}
else
{
header(Location:failed.php);
}
}
if(!$action) {
?>
<form action="?action=login" method="post">
<p>USER NAME :
<input type="text" name="user">
</p>
<p>PASSWORD :
<input type="password" name="pass">
<input type="button" value="Login" name="Submit">
</p>
</form>
<?php
}
?>
Reg Web
August 8th, 2005, 17:12
is there a way of making sure they can only view the pages when logged in?
R4g1ng
August 9th, 2005, 04:56
Use sessions or cookies. Sessions destroyed when the browser is closed and cookies are stored on the computer. But some people may disable cookies. So I recommend you use both.
<?php
if($action=="login") {
$user = $_POST['user'];
$pass = $_POST['pass'];
if(($user == "user1" && $pass == "pass1") || ($user == "user2" && $pass == "pass2")) {
$pw = md5($pass); // Encrypt the password
setcookie ("auth",$user-$pw,time()+1957240,"/"); // Create the cookie, storing the username and encrypted pass.
session_register("auth"); // set a session in case cookies are disabled
header(Location:frontpage.php);
}
else
{
header(Location:failed.php);
}
}
if(!$action) {
?>
<form action="?action=login" method="post">
<p>USER NAME :
<input type="text" name="user">
</p>
<p>PASSWORD :
<input type="password" name="pass">
<input type="button" value="Login" name="Submit">
</p>
</form>
<?php
}
?>
Now to make sure the cookie or session is set, on frontpage.php or the pages you want to be protected put this on the top, very top or you'll get header errors.
<?php
$cookie = $_COOKIE['auth'];
session_start(); // You need this to read session variables
if (empty($cookie) || !isset($cookie)) // if the cookie is empty or not set
{
// Read the session
if (empty($_SESSION['auth']) || !isset($_SESSION['auth'])) // the session is empty or not set
{
header("Location: login.php"); // Redirect to login.php
exit; // Stop any further coding
}
?>
Reg Web
August 9th, 2005, 05:34
Thanks, I'll get to work now.
rolly
August 9th, 2005, 09:52
see this post on this forum
http://freewebspace.net/forums/showpost.php?p=579047&postcount=15
i hope, it helps you.
Reg Web
September 27th, 2005, 13:13
Rolly: your script is fine, but it is in ASP, so I cannot use it!
R4g1ng: Cannot test your script as nothing happens when I click "login"!
Can anyone please help me with this?
R4g1ng
September 28th, 2005, 06:38
<?php
if($action=="login") {
$user = $_POST['user'];
$pass = $_POST['pass'];
if(($user == "user1" && $pass == "pass1") || ($user == "user2" && $pass == "pass2")) {
$pw = md5($pass); // Encrypt the password
setcookie ("auth",$user-$pw,time()+1957240,"/"); // Create the cookie, storing the username and encrypted pass.
session_register("auth"); // set a session in case cookies are disabled
header(Location:frontpage.php);
}
else
{
header(Location:failed.php);
}
}
?>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>?action=login" method="post">
<p>USER NAME :
<input type="text" name="user">
</p>
<p>PASSWORD :
<input type="password" name="pass">
<input type="submit" value="Login" name="submit">
</p>
</form>
Reg Web
September 29th, 2005, 12:15
Thank you!
- Dan
October 5th, 2005, 12:03
Hi R4Ging.. Nice tutorial :) I learn more now :)
Just wonder let say that I will have a login form. Then after user login then the login form will change to
Hello $_POST['user'],
Then there are two links cpanel and billing.
Is there any way that with those login information the user can directly login to cpanel page and billing?
In this case I think it will need to integrate with clientexec database maybe.
Sorry a bit not clear english :)
Anyway. Is there any possibility one login, that will access to two logins (cPanel and billing (cilentexec))? Let say this case user & password is same.
I think it will be hard if the user and password different.
Thanks
Dan^^
R4g1ng
October 6th, 2005, 04:28
I'm not sure because I don't know anything about the coding in those scripts. You might need someone more experienced to answer that question.
- Dan
October 6th, 2005, 07:15
Oh that's fine ^^ Just wonder since you explain it very clear :)
Dan ^^
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.