Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Web Design & Development
Tag Cloud
access audio black screen blue screen boot bsod connection crash desktop driver drivers dvd email error excel firefox hard drive hardware hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem processor recovery router safe mode screen slow sound spyware tdlwsp.dll trojan upgrade vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: Help with request of Access Password when page is opened

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

 
Thread Tools
Omovie's Avatar
Computer Specs
Junior Member with 19 posts.
 
Join Date: Oct 2009
Experience: Web Application
20-Oct-2009, 05:30 AM #1
Thumbs up Solved: Help with request of Access Password when page is opened
Am a beginner in programming.
<li>I want to know if it is possible to add password to a particular page ,if someone wants to view the content of that page
, it will ask the visitor to type in his/her password. the password will be such that i have have given to that person to access that page.</li>

<li> Is it also possible to give different password to different people to access that page?</li>

<li>In this case, the viewer does not need to have registered</li>

Can somebody in the house please help me out with the codes?
holyhttp's Avatar
Computer Specs
Junior Member with 19 posts.
 
Join Date: Oct 2009
Location: Hayward, CA
Experience: Dreamweaver, CSS, HTML
20-Oct-2009, 08:47 PM #2
You can for example create a PHP web page (or any other language) and hard-code the password in there.

You can have the page display an login form the user can fill out. If the password submitted checked out against what you hard coded then that visitor will be shown the information that is password protected.

Here is a sample just for you:


<?php
$validlogin=false;
$thepass=arry('pass1', 'pass2', 'pass3');
//=====================================================================
//=====================================================================
if(isset($_COOKIE['valilogin']) && $_COOKIE['valilogin']=='userOK'){
$validlogin=true;
}
else if( isset($_REQUEST['userpass']) && in_array($_REQUEST['userpass'],$thepass)){
$validlogin=true;
}

//=====================================================================
//=====================================================================
if($validlogin){
setcookie('validlogin', 'userOK', time()+7200);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Your web page Title</title>
</head>
<body>
<?php if($validlogin){
//=========================================================================== =============
?>
Put web page information here. This will not be visible unless the user is already logged in.
<?php } else { ?>
<form action="" method="post" name="loginform">
<label>Your Password</label>
<input type="password" name="userpass" value="" />
<input name="btnsubmit" type="button" value="Login" />
</form>
<?php } ?>
</body>
</html>
Omovie's Avatar
Computer Specs
Junior Member with 19 posts.
 
Join Date: Oct 2009
Experience: Web Application
22-Oct-2009, 03:14 PM #3
Access Codes Pass
Guy thanks for your code, i have tried it is not working. am online now.Is anybody there to help me out
holyhttp's Avatar
Computer Specs
Junior Member with 19 posts.
 
Join Date: Oct 2009
Location: Hayward, CA
Experience: Dreamweaver, CSS, HTML
22-Oct-2009, 03:59 PM #4
<?php
$validlogin=false;
$thepass=array('pass1', 'pass2', 'pass3');
//=====================================================================
//=====================================================================
if(isset($_COOKIE['validlogin']) && $_COOKIE['validlogin']=='userOK'){
$validlogin=true;
}
else if(isset($_POST['userpass']) && $_POST['userpass']!=''){
foreach($thepass as $key=>$value){
if(trim($_POST['userpass'])==$value){
$validlogin=true;
break;
}
}
}
//=====================================================================
//=====================================================================
if($validlogin){
setcookie('validlogin', 'userOK', time()+3600);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Your web page Title</title>
</head>
<body>
<?php if($validlogin){ ?>
Put web page information here. This will not be visible unless the user is already logged in.<br />
.....................................<br />
.....................................<br />
.....................................<br />
<?php } else { ?>
<form action="" method="post" name="loginform">
<label>Your Password</label>
<input type="password" name="userpass" value="" />
<input name="btnsubmit" type="submit" value="Login" />
</form>
<?php } ?>
</body>
</html>
holyhttp's Avatar
Computer Specs
Junior Member with 19 posts.
 
Join Date: Oct 2009
Location: Hayward, CA
Experience: Dreamweaver, CSS, HTML
22-Oct-2009, 04:02 PM #5
If you compare the code above with the one in the first reply then only difference is on the third line (array instead of arry)
and the 5th line from the bottom (type="submit" instead of type="button").
It should work now.

You just need to defined the preset passwords inside the array, properly format your form and enter the correct information that would be display when the login is successful.
Omovie's Avatar
Computer Specs
Junior Member with 19 posts.
 
Join Date: Oct 2009
Experience: Web Application
23-Oct-2009, 08:40 AM #6
Thanks bro. I have even changed the "arry" to "array" and the "button" to "submit". You really tried. You my brother. Thanks alot.
holyhttp's Avatar
Computer Specs
Junior Member with 19 posts.
 
Join Date: Oct 2009
Location: Hayward, CA
Experience: Dreamweaver, CSS, HTML
23-Oct-2009, 10:34 AM #7
I have tested the script and it works. I am not sure what seems to be the issue on the machine you are running it on.
Omovie's Avatar
Computer Specs
Junior Member with 19 posts.
 
Join Date: Oct 2009
Experience: Web Application
23-Oct-2009, 10:52 AM #8
The script is working now. am not saying that is not working. Am just thanking you. I have even use it on my web page and is working. Thanks Bro
holyhttp's Avatar
Computer Specs
Junior Member with 19 posts.
 
Join Date: Oct 2009
Location: Hayward, CA
Experience: Dreamweaver, CSS, HTML
23-Oct-2009, 11:43 AM #9
I am glad. The use of :you really tried" led me to believe it did not work and that you gave up.
briealeida's Avatar
Computer Specs
Senior Member with 660 posts.
 
Join Date: Jun 2007
Location: US and A
Experience: Ninja
26-Oct-2009, 12:20 PM #10
This may help someone in the future, but you can do this with .htaccess as well. (Some people don't have access to PHP).

http://www.javascriptkit.com/howto/htaccess3.shtml
Omovie's Avatar
Computer Specs
Junior Member with 19 posts.
 
Join Date: Oct 2009
Experience: Web Application
27-Oct-2009, 04:07 AM #11
You people Have been wonderful. You have really helped me proved that i can do it. The codes worked perfectly well. am most g8tfull for your support and help. Love yeah
Reply Bookmark and Share

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 02:51 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.