Ok I Have Gotten This Script That Protects Certain Pages With A Username And Password from this site :: Web Page Password Protect :: Free PHP Scripts and i want to put a chat page on my website that requires a username and password before entering, i was wondering if there is any way i can make a sign up form with username and password fields that, when i click submit it copies the username and password typed in the form into the Password Protect script giving the user immediate access to the chat page after signing up.
Any Help Would Be Dearly Appreciated
Thanks. Jack :) :lol:
Login Script - Help
Started by jthom263, Apr 11 2010 09:09 PM
15 replies to this topic
#1
Posted 11 April 2010 - 09:09 PM
|
|
|
#2
Posted 11 April 2010 - 10:11 PM
You mean the user is automaticly logged in after signing up?
Usually login systems are based on SESSIONS or COOKIES, for example a session 'logged' would be checked to be set to TRUE to check if the user is loggedin and whether the sessions 'username' and 'password' are valid ( for example ). So just creating these sessions for the user instantly after signing up ( just as happens when the user logs in ) would do the job.
Not sure if this is what you mean though.
EDIT: will check the script when I get back from work =].
checked script quickly, seems to work based on cookies, must say the script seems bit messy but looks like this makes the user logs in:
Put it in your script for the signup script ( upon signing up this script would be executed ).
</SPAN>But again, could be wong, just checked the script quickly ;)
Usually login systems are based on SESSIONS or COOKIES, for example a session 'logged' would be checked to be set to TRUE to check if the user is loggedin and whether the sessions 'username' and 'password' are valid ( for example ). So just creating these sessions for the user instantly after signing up ( just as happens when the user logs in ) would do the job.
Not sure if this is what you mean though.
EDIT: will check the script when I get back from work =].
checked script quickly, seems to work based on cookies, must say the script seems bit messy but looks like this makes the user logs in:
$login = "put the (POST?) variable containing the user signed up login username here";
$pass = "put the (POST?) variable containing the user signed up login password here";
$timeout = "amount of seconds the user should remain loggedin";
// set cookie if password was validated
setcookie("verify", md5($login.'%'.$pass), $timeout, '/');
Put it in your script for the signup script ( upon signing up this script would be executed ).
</SPAN>But again, could be wong, just checked the script quickly ;)
#3
Posted 11 April 2010 - 10:27 PM
Thanks For The Reply :):w00t: Sorry About Not Explaining Myself Very Well I Am New To Forums... This Is What I Mean Here Is The Script I Have In Bold The Part Of The Script I Mean And My Question Next To It In Bold
I Don't Really Know Much About Php Either So Please Explain In Depth.
Thank-You In Advance. :):lol:
<?php
###############################################################
# Page Password Protect 2.13
###############################################################
# Visit :: Free PHP Scripts for updates
###############################################################
#
# Usage:
# Set usernames / passwords below between SETTINGS START and SETTINGS END.
# Open it in browser with "help" parameter to get the code
# to add to all files being protected.
# Example: password_protect.php?help
# Include protection string which it gave you into every file that needs to be protected
#
# Add following HTML code to your page where you want to have logout link
# <a href="http://www.example.com/path/to/protected/page.php?logout=1">Logout</a>
#
###############################################################
/*
-------------------------------------------------------------------
SAMPLE if you only want to request login and password on login form.
Each row represents different user.
$LOGIN_INFORMATION = array(
'zubrag' => 'root',
'test' => 'testpass',
'admin' => 'passwd'
);
--------------------------------------------------------------------
SAMPLE if you only want to request only password on login form.
Note: only passwords are listed
$LOGIN_INFORMATION = array(
'root',
'testpass',
'passwd'
);
--------------------------------------------------------------------
*/
##################################################################
# SETTINGS START
##################################################################
// Add login/password pairs below, like described above
// NOTE: all rows except last must have comma "," at the end of line
$LOGIN_INFORMATION = array(
'user' => 'pass1',
'user2' => 'pass2'
);
#I Want To Make A Form + Script That Adds A Username And Password To This So People Can Sign Up And It Copies The Information From The Username And Password Fields To Where "User" And "Pass1" Are
// request login? true - show login and password boxes, false - password box only
define('USE_USERNAME', true);
// User will be redirected to this page after logout
define('LOGOUT_URL', 'http://www.example.com/');
// time out after NN minutes of inactivity. Set to 0 to not timeout
define('TIMEOUT_MINUTES', 10);
// This parameter is only useful when TIMEOUT_MINUTES is not zero
// true - timeout time from last activity, false - timeout time from login
define('TIMEOUT_CHECK_ACTIVITY', true);
##################################################################
# SETTINGS END
##################################################################
///////////////////////////////////////////////////////
// do not change code below
///////////////////////////////////////////////////////
// show usage example
if(isset($_GET['help'])) {
die('Include following code into every page you would like to protect, at the very beginning (first line):<br><?php include("' . str_replace('\\','\\\\',__FILE__) . '"); ?>');
}
// timeout in seconds
$timeout = (TIMEOUT_MINUTES == 0 ? 0 : time() + TIMEOUT_MINUTES * 60);
// logout?
if(isset($_GET['logout'])) {
setcookie("verify", '', $timeout, '/'); // clear password;
header('Location: ' . LOGOUT_URL);
exit();
}
if(!function_exists('showLoginPasswordProtect')) {
// show login form
function showLoginPasswordProtect($error_msg) {
?>
<html>
<head>
<title>Please enter password to access this page</title>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body bgcolor="#0000FF">
<style>
input { border: 1px solid black; }
</style>
<div style="width:500px; margin-left:auto; margin-right:auto; text-align:center">
<form method="post">
<h3>Please enter password to access this page</h3>
<font color="red"><?php echo $error_msg; ?></font><br />
<?php if (USE_USERNAME) echo 'Login:<br /><input type="input" name="access_login" /><br />Password:<br />'; ?>
<input type="password" name="access_password" /><p></p><input type="submit" name="Submit" value="Submit" />
</form>
<p><br />
<a style="font-size:9px; color: #B0B0B0; font-family: Verdana, Arial;" href="http://www.zubrag.com/scripts/password-protect.php" title="Download Password Protector">Powered by Password Protect</a>
</p>
<p> </p>
<p><a href="Apply.html">Apply For Username And Password</a></p>
</div>
</body>
</html>
<?php
// stop at this point
die();
}
}
// user provided password
if (isset($_POST['access_password'])) {
$login = isset($_POST['access_login']) ? $_POST['access_login'] : '';
$pass = $_POST['access_password'];
if (!USE_USERNAME && !in_array($pass, $LOGIN_INFORMATION)
|| (USE_USERNAME && ( !array_key_exists($login, $LOGIN_INFORMATION) || $LOGIN_INFORMATION[$login] != $pass ) )
) {
showLoginPasswordProtect("Incorrect password.");
}
else {
// set cookie if password was validated
setcookie("verify", md5($login.'%'.$pass), $timeout, '/');
// Some programs (like Form1 Bilder) check $_POST array to see if parameters passed
// So need to clear password protector variables
unset($_POST['access_login']);
unset($_POST['access_password']);
unset($_POST['Submit']);
}
}
else {
// check if password cookie is set
if (!isset($_COOKIE['verify'])) {
showLoginPasswordProtect("");
}
// check if cookie is good
$found = false;
foreach($LOGIN_INFORMATION as $key=>$val) {
$lp = (USE_USERNAME ? $key : '') .'%'.$val;
if ($_COOKIE['verify'] == md5($lp)) {
$found = true;
// prolong timeout
if (TIMEOUT_CHECK_ACTIVITY) {
setcookie("verify", md5($lp), $timeout, '/');
}
break;
}
}
if (!$found) {
showLoginPasswordProtect("");
}
}
?>
I Don't Really Know Much About Php Either So Please Explain In Depth.
Thank-You In Advance. :):lol:
Edited by Jaan, 12 April 2010 - 07:09 AM.
Please use code tags when you are posting your codes!
#4
Posted 11 April 2010 - 10:32 PM
Thanks For The Reply. Sorry For Not Explaining Myself Very Well, I'm New To Forums.... Here Is The Code I'll Put In Bold What I Mean :D :)
I Don't Know Much About PHP So Please Explain In Depth.
Thanks In Advance :cool::w00t:
<?php
###############################################################
# Page Password Protect 2.13
###############################################################
# Visit :: Free PHP Scripts for updates
###############################################################
#
# Usage:
# Set usernames / passwords below between SETTINGS START and SETTINGS END.
# Open it in browser with "help" parameter to get the code
# to add to all files being protected.
# Example: password_protect.php?help
# Include protection string which it gave you into every file that needs to be protected
#
# Add following HTML code to your page where you want to have logout link
# <a href="http://www.example.com/path/to/protected/page.php?logout=1">Logout</a>
#
###############################################################
/*
-------------------------------------------------------------------
SAMPLE if you only want to request login and password on login form.
Each row represents different user.
$LOGIN_INFORMATION = array(
'zubrag' => 'root',
'test' => 'testpass',
'admin' => 'passwd'
);
--------------------------------------------------------------------
SAMPLE if you only want to request only password on login form.
Note: only passwords are listed
$LOGIN_INFORMATION = array(
'root',
'testpass',
'passwd'
);
--------------------------------------------------------------------
*/
##################################################################
# SETTINGS START
##################################################################
// Add login/password pairs below, like described above
// NOTE: all rows except last must have comma "," at the end of line
$LOGIN_INFORMATION = array(
'user' => 'pass1',
'user2' => 'pass2'
#I Want To Make A Sign Up Form/Script That Copies The Username And Password Fields Content Into Where "User1" And "Pass1" Are.
);
// request login? true - show login and password boxes, false - password box only
define('USE_USERNAME', true);
// User will be redirected to this page after logout
define('LOGOUT_URL', 'http://www.example.com/');
// time out after NN minutes of inactivity. Set to 0 to not timeout
define('TIMEOUT_MINUTES', 10);
// This parameter is only useful when TIMEOUT_MINUTES is not zero
// true - timeout time from last activity, false - timeout time from login
define('TIMEOUT_CHECK_ACTIVITY', true);
##################################################################
# SETTINGS END
##################################################################
///////////////////////////////////////////////////////
// do not change code below
///////////////////////////////////////////////////////
// show usage example
if(isset($_GET['help'])) {
die('Include following code into every page you would like to protect, at the very beginning (first line):<br><?php include("' . str_replace('\\','\\\\',__FILE__) . '"); ?>');
}
// timeout in seconds
$timeout = (TIMEOUT_MINUTES == 0 ? 0 : time() + TIMEOUT_MINUTES * 60);
// logout?
if(isset($_GET['logout'])) {
setcookie("verify", '', $timeout, '/'); // clear password;
header('Location: ' . LOGOUT_URL);
exit();
}
if(!function_exists('showLoginPasswordProtect')) {
// show login form
function showLoginPasswordProtect($error_msg) {
?>
<html>
<head>
<title>Please enter password to access this page</title>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body bgcolor="#0000FF">
<style>
input { border: 1px solid black; }
</style>
<div style="width:500px; margin-left:auto; margin-right:auto; text-align:center">
<form method="post">
<h3>Please enter password to access this page</h3>
<font color="red"><?php echo $error_msg; ?></font><br />
<?php if (USE_USERNAME) echo 'Login:<br /><input type="input" name="access_login" /><br />Password:<br />'; ?>
<input type="password" name="access_password" /><p></p><input type="submit" name="Submit" value="Submit" />
</form>
<p><br />
<a style="font-size:9px; color: #B0B0B0; font-family: Verdana, Arial;" href="http://www.zubrag.com/scripts/password-protect.php" title="Download Password Protector">Powered by Password Protect</a>
</p>
<p> </p>
<p><a href="Apply.html">Apply For Username And Password</a></p>
</div>
</body>
</html>
<?php
// stop at this point
die();
}
}
// user provided password
if (isset($_POST['access_password'])) {
$login = isset($_POST['access_login']) ? $_POST['access_login'] : '';
$pass = $_POST['access_password'];
if (!USE_USERNAME && !in_array($pass, $LOGIN_INFORMATION)
|| (USE_USERNAME && ( !array_key_exists($login, $LOGIN_INFORMATION) || $LOGIN_INFORMATION[$login] != $pass ) )
) {
showLoginPasswordProtect("Incorrect password.");
}
else {
// set cookie if password was validated
setcookie("verify", md5($login.'%'.$pass), $timeout, '/');
// Some programs (like Form1 Bilder) check $_POST array to see if parameters passed
// So need to clear password protector variables
unset($_POST['access_login']);
unset($_POST['access_password']);
unset($_POST['Submit']);
}
}
else {
// check if password cookie is set
if (!isset($_COOKIE['verify'])) {
showLoginPasswordProtect("");
}
// check if cookie is good
$found = false;
foreach($LOGIN_INFORMATION as $key=>$val) {
$lp = (USE_USERNAME ? $key : '') .'%'.$val;
if ($_COOKIE['verify'] == md5($lp)) {
$found = true;
// prolong timeout
if (TIMEOUT_CHECK_ACTIVITY) {
setcookie("verify", md5($lp), $timeout, '/');
}
break;
}
}
if (!$found) {
showLoginPasswordProtect("");
}
}
?>
I Don't Know Much About PHP So Please Explain In Depth.
Thanks In Advance :cool::w00t:
Edited by Jaan, 12 April 2010 - 07:10 AM.
Please use code tags when you are posting your codes!
#5
Posted 11 April 2010 - 11:20 PM
Thanks For The Reply. Sorry For The Late Reply From Me It Was Saying Must Be Approved By Moderators And Nothing Was Happening Here Is What I Mean.
'user1' => 'pass1',
'user2' => 'pass2'
#I Want To Make A Form/Script That Adds The Username And Pass That Was Typed In the Form To This List. That Is What I Want To Know.
I Don't Know Too Much About Php So Please Explain In Detail.
Thanks In Advance
Jack :cool: :w00t:
<?php ############################################################### # Page Password Protect 2.13 ############################################################### # Visit http://www.zubrag.com/scripts/ for updates ############################################################### # # Usage: # Set usernames / passwords below between SETTINGS START and SETTINGS END. # Open it in browser with "help" parameter to get the code # to add to all files being protected. # Example: password_protect.php?help # Include protection string which it gave you into every file that needs to be protected # # Add following HTML code to your page where you want to have logout link # <a href="http://www.example.com/path/to/protected/page.php?logout=1">Logout</a> # ############################################################### /* ------------------------------------------------------------------- SAMPLE if you only want to request login and password on login form. Each row represents different user. $LOGIN_INFORMATION = array( 'zubrag' => 'root', 'test' => 'testpass', 'admin' => 'passwd' ); -------------------------------------------------------------------- SAMPLE if you only want to request only password on login form. Note: only passwords are listed $LOGIN_INFORMATION = array( 'root', 'testpass', 'passwd' ); -------------------------------------------------------------------- */ ################################################################## # SETTINGS START ################################################################## // Add login/password pairs below, like described above // NOTE: all rows except last must have comma "," at the end of line $LOGIN_INFORMATION = array( 'user1' => 'pass1', 'user2' => 'pass2' #I Want To Make A Form/Script That Adds The Username ANd Pass That Was Typed In the Form To This List. ); // request login? true - show login and password boxes, false - password box only define('USE_USERNAME', true); // User will be redirected to this page after logout define('LOGOUT_URL', 'http://www.example.com/'); // time out after NN minutes of inactivity. Set to 0 to not timeout define('TIMEOUT_MINUTES', 10); // This parameter is only useful when TIMEOUT_MINUTES is not zero // true - timeout time from last activity, false - timeout time from login define('TIMEOUT_CHECK_ACTIVITY', true); ################################################################## # SETTINGS END ################################################################## /////////////////////////////////////////////////////// // do not change code below /////////////////////////////////////////////////////// // show usage example if(isset($_GET['help'])) { die('Include following code into every page you would like to protect, at the very beginning (first line):<br><?php include("' . str_replace('\\','\\\\',__FILE__) . '"); ?>'); } // timeout in seconds $timeout = (TIMEOUT_MINUTES == 0 ? 0 : time() + TIMEOUT_MINUTES * 60); // logout? if(isset($_GET['logout'])) { setcookie("verify", '', $timeout, '/'); // clear password; header('Location: ' . LOGOUT_URL); exit(); } if(!function_exists('showLoginPasswordProtect')) { // show login form function showLoginPasswordProtect($error_msg) { ?> <html> <head> <title>Please enter password to access this page</title> <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head> <body bgcolor="#0000FF"> <style> input { border: 1px solid black; } </style> <div style="width:500px; margin-left:auto; margin-right:auto; text-align:center"> <form method="post"> <h3>Please enter password to access this page</h3> <font color="red"><?php echo $error_msg; ?></font><br /> <?php if (USE_USERNAME) echo 'Login:<br /><input type="input" name="access_login" /><br />Password:<br />'; ?> <input type="password" name="access_password" /><p></p><input type="submit" name="Submit" value="Submit" /> </form> <p><br /> <a style="font-size:9px; color: #B0B0B0; font-family: Verdana, Arial;" href="http://www.zubrag.com/scripts/password-protect.php" title="Download Password Protector">Powered by Password Protect</a> </p> <p> </p> <p><a href="Apply.html">Apply For Username And Password</a></p> </div> </body> </html> <?php // stop at this point die(); } } // user provided password if (isset($_POST['access_password'])) { $login = isset($_POST['access_login']) ? $_POST['access_login'] : ''; $pass = $_POST['access_password']; if (!USE_USERNAME && !in_array($pass, $LOGIN_INFORMATION) || (USE_USERNAME && ( !array_key_exists($login, $LOGIN_INFORMATION) || $LOGIN_INFORMATION[$login] != $pass ) ) ) { showLoginPasswordProtect("Incorrect password."); } else { // set cookie if password was validated setcookie("verify", md5($login.'%'.$pass), $timeout, '/'); // Some programs (like Form1 Bilder) check $_POST array to see if parameters passed // So need to clear password protector variables unset($_POST['access_login']); unset($_POST['access_password']); unset($_POST['Submit']); } } else { // check if password cookie is set if (!isset($_COOKIE['verify'])) { showLoginPasswordProtect(""); } // check if cookie is good $found = false; foreach($LOGIN_INFORMATION as $key=>$val) { $lp = (USE_USERNAME ? $key : '') .'%'.$val; if ($_COOKIE['verify'] == md5($lp)) { $found = true; // prolong timeout if (TIMEOUT_CHECK_ACTIVITY) { setcookie("verify", md5($lp), $timeout, '/'); } break; } } if (!$found) { showLoginPasswordProtect(""); } } ?>$LOGIN_INFORMATION = array(
'user1' => 'pass1',
'user2' => 'pass2'
#I Want To Make A Form/Script That Adds The Username And Pass That Was Typed In the Form To This List. That Is What I Want To Know.
I Don't Know Too Much About Php So Please Explain In Detail.
Thanks In Advance
Jack :cool: :w00t:
#6
Posted 12 April 2010 - 12:43 AM
Like this?
<?php
if($_POST['submit']) {
$LOGIN_INFORMATION['user3'] = "pass3";
//or with form date:
$LOGIN_INFORMATION[$_POST['user']] = $_POST['pass'];
}else{
?>
<form method="POST" action="<?=$_SERVER['PHP_SELF'];?>">
<input type='text' name='user'>
<input type='password' name='pass'>
<input type='submit' name='submit'>
</form>
<?php
}
?>
#7
Posted 12 April 2010 - 12:48 AM
SO Will That Post The Username And Password Typed In After
So IF I Type In For Username "Jack"
And For Password "123"
It Will Now Appear Like This:
?
Thus Adding Another User
P.S. The Name Of The Script I Want To Add The Users To Is "Password_Protect.php"
$LOGIN_INFORMATION = array( 'user1' => 'pass1', 'user2' => 'pass2'
So IF I Type In For Username "Jack"
And For Password "123"
It Will Now Appear Like This:
$LOGIN_INFORMATION = array( 'user1' => 'pass1', 'user2' => 'pass2' 'Jack' => '123'
?
Thus Adding Another User
P.S. The Name Of The Script I Want To Add The Users To Is "Password_Protect.php"
Edited by Jaan, 12 April 2010 - 07:11 AM.
Please use code tags when you are posting your codes!
#8
Posted 12 April 2010 - 12:55 AM
Yes that's correct :).
And it doesn't add it to a "script" but to an array created inside the script, like:
and will only be saved inside the variable untill the page is refreshed, so it should be used within that script immediately otherwise it's useless.
And it doesn't add it to a "script" but to an array created inside the script, like:
<?php
include("Password_protect.php");
$LOGIN_INFORMATION['Jack'] = '123';
?>
and will only be saved inside the variable untill the page is refreshed, so it should be used within that script immediately otherwise it's useless.
#9
Posted 12 April 2010 - 12:58 AM
Ok I'll Give It A Go
#10
Posted 12 April 2010 - 01:02 AM
<?php
if($_POST['submit']) {
$LOGIN_INFORMATION['user3'] = "pass3";
//or with form date:
$LOGIN_INFORMATION[$_POST['user']] = $_POST['pass'];
}else{
?>
<form method="POST" action="<?=$_SERVER['PHP_SELF'];?>">
<input type='text' name='user'>
<input type='password' name='pass'>
<input type='submit' name='submit'>
</form>
<?php
}
?> in this Script How Do I tell It that The Target Is "Password_Protect.php" ?
#11
Posted 12 April 2010 - 01:03 AM
ohhhh
<?php
if($_POST['submit']) {
$LOGIN_INFORMATION['user3'] = "pass3";
//or with form date:
$LOGIN_INFORMATION[$_POST['user']] = $_POST['pass'];
}else{
?>
<form method="POST" action="<?=$_SERVER['Password_Protect.php'];?>">
<input type='text' name='user'>
<input type='password' name='pass'>
<input type='submit' name='submit'>
</form>
<?php
}
?> That Right????
#12
Posted 12 April 2010 - 01:33 AM
Ok I've Tried It But It Doesn't Actually Add The Username And Password To The password_protect.php Here Have A Look Http://jackthompsonstestingserver.byethost4.com On The Login Page There Is A Link To The Sign Up Script But U Can Hardly See It So Look CLosely LOLz


Sign In
Create Account


Back to top









