Jump to content

How To Create Html Page With User And Pass


Dr-SeMSeM

Recommended Posts

Hello everybody i wanna to ask about mini issuei want to create an index with domain name , once i open the page link asking me about user name and pass ( stored in page information or any other way )something like this picture25oyix2.jpgplease tell me how to create a page like this , once i type to true user and pass ... i can sea the content ..if now .. giving me access denied or worng user or pass ?thanks for help

Link to comment
Share on other sites

its only one user name and one password ... not multible useres .. only one user and one password .. i think it can be created using Java .. but what is the code if it can do it ..its about a name and password to view page only ...

Link to comment
Share on other sites

Java on the server side, yes, it can be done. Or PHP. Have it clear: Java is not Javascript.However it won't show that box that's in your screenshot, you'd have to make an HTML form asking for the name and password and then check it on the server.

Link to comment
Share on other sites

With a server-side language you can set HTTP 401 and send www-authenticate:basic to get the "native" authentication dialog like in the screenshot.

Link to comment
Share on other sites

one of my friends told me that its will be better to create it but as PHP page with config file where i canwrite the user and pass what i want to view content of this page ..if it possible with php page please tell me how to do it or give me the code because im not a programmer ..i just designer ...thanks for advance :)

Link to comment
Share on other sites

Below is the code which will work for a single set of username and password. You can change username and password accordingly. Currently both the username as well as password is botskool. You need to create three files -

  • login.php
  • main.php
  • logout.php

Code for login.php -

<?phpsession_start(); $errorMessage = '';if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {if ($_POST['txtUserId'] === 'botskool' && $_POST['txtPassword'] === 'botskool') {$_SESSION['basic_is_logged_in'] = true;header('Location: main.php');		//give your own relative url hereexit;} else {$errorMessage = 'Sorry, wrong user Id / password';}}?><html><head><title>Basic Login</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head> <body><?phpif ($errorMessage != '') {?><p align="center"><strong><font color="#990000"><?php echo $errorMessage; ?></font></strong></p><?php}?> <form method="post" name="frmLogin" id="frmLogin"><table width="400" border="1" align="center" cellpadding="2" cellspacing="2"><tr><td width="150">User Id</td><td><input name="txtUserId" type="text" id="txtUserId"></td></tr><tr><td width="150">Password</td><td><input name="txtPassword" type="password" id="txtPassword"></td></tr><tr><td width="150"> </td><td><input type="submit" name="btnLogin" value="Login"></td></tr></table></form></body></html>

Code for main.php -

<?phpsession_start();if (!isset($_SESSION['basic_is_logged_in']) || $_SESSION['basic_is_logged_in'] !== true) {	header('Location: login.php');	exit;}?><html><head><title>Main User Page</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><p>This is the area where you can place your content that is to be viewed. :-) </p><p> </p><p><a href="logout.php">Logout</a> </p></body></html>

Change the content of main.php according to your needs.Code for logout.php-

<?phpsession_start();if (isset($_SESSION['basic_is_logged_in'])){   unset($_SESSION['basic_is_logged_in']);}header('Location: login.php');?>

Hope this helps :) Good luck!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...