Peace
Login and Password with PHP
Moderator: General Moderators
- Mexican Hat
- Forum Newbie
- Posts: 19
- Joined: Sat Mar 08, 2003 8:35 pm
- Location: Baltimore, Maryland
- Contact:
Login and Password with PHP
I pretty much know nothing about PHP so I need some help making a code that allows users to login to their account. If anyone could help me that would be great. I'm not really going to have a lot of members on my site so I just need a simple code.
Peace
Peace
put this into a script login.php and in all your other pages include it in the first line as
<? include ('login.php'); ?>
<? include ('login.php'); ?>
Code: Select all
<?php
function valid_login($username, $password) {
return ($username == 'elipollak' && $password == 'pass');
}
function login_screen($failed = 0) {
$output = "<HTML>"
."<HEAD><LINK REL=StyleSheet HREF="_style.css" TYPE="text/css"></HEAD>"
."<BODY bgcolor=#e1e1e1><center>"
."<form action='". $_SERVER['PHP_SELF']. "' method='post'>"
."<table border = 0>"
."<TR><TD>Username:<TD><input type='text' name='username' maxlength='20'>"
."<TR><TD>Password: <TD><input type='password' name='password' maxlength='20'>"
."<TR><TD colspan=2><center><input type='submit' name='submit' value='Login'>"
."</table>"
."</form>"
."<BR><BR>";
if ($failed) $output .= "<font color = red><b>Failed ".$_SESSION['count']." time(s) : Keep Trying Biatch</b></font>";
return $output ."<BR><BR></center></body></html>";
}
session_start();
if( ! isset($_SESSION['count']) ) $_SESSION['count'] = 0;
else $_SESSION['count']++;
if( ! isset($_SESSION['logged_in']) ) {
if ( ! isset($_POST['submit'])) {
die (login_screen());
} elseif ( valid_login($_POST['username'], $_POST['password']) ) {
$_SESSION['count'] = 1;
$_SESSION['logged_in'] = 1;
} elseif ( $_SESSION['count'] > 3 ) {
header("Location: baby/index.html");
exit;
} else {
die ( login_screen($failed = 1) );
}
}
?>- Mexican Hat
- Forum Newbie
- Posts: 19
- Joined: Sat Mar 08, 2003 8:35 pm
- Location: Baltimore, Maryland
- Contact:
Thanks
Thanks for the code. I have one question. Where do I put the PHP file? In the cgi-bin or just with the rest of my site.
Peace
Peace
- Slyvampy
- Forum Newbie
- Posts: 23
- Joined: Thu Nov 28, 2002 2:03 am
- Location: Yorkshire, England
- Contact:
The PHP page you are coding is the site. it replaces or complements the html pages.
HTML pages are static, PHP are server side scripting pages and are dynamic.
ie. you would put this code at the top of your page, rename the extention on your page
if you need advice at any time, email me. (webmaster@slyvampy.com)
Cheers,
SteJ.
HTML pages are static, PHP are server side scripting pages and are dynamic.
ie. you would put this code at the top of your page, rename the extention on your page
instead of.php
the output would be the html code..html or .htm
if you need advice at any time, email me. (webmaster@slyvampy.com)
Cheers,
SteJ.
- Mexican Hat
- Forum Newbie
- Posts: 19
- Joined: Sat Mar 08, 2003 8:35 pm
- Location: Baltimore, Maryland
- Contact:
Ok I understand Now
Ok I understand now. I just put my html in the PHP script. What I don't understand is how to make the username and passwords. I'm going to be the one who puts the name and passwords for people. I don't want it where is does it for them. Do the username and passwords go in the php file some where.
Peace
Peace
- Mexican Hat
- Forum Newbie
- Posts: 19
- Joined: Sat Mar 08, 2003 8:35 pm
- Location: Baltimore, Maryland
- Contact: