How to create LOGIN AREA (register,log in)

thnx 2 all my script is working…

hey guys, im trying to make a login area on my website to restrict access only to teachers. I have tried using the “Password Protect Directory” option and i keep getting an error about using unrecognised characters when in fact i am only using characters recognised (A-Z, a-z, 0-9, underscore and dash) I am not good with coding so i am looking for the most simplest and easiest way to do this… I Appreciate any help, and will give some of the above suggestions a whirl…

Olimpiacara69 take a look at: http://tools.dynamicdrive.com/password/

It’s basically the manual way of doing “Password protect directory”

LMillward, thanks for your help. I tried that website and it seemed to go good. I made the .htaccess and .htpasswd files yet i still cant get a username and password to come up on the directory i want to protect… any ideas?

Just gave it a try and it works: http://laurencemillward.comyr.com/test/

My .htaccess is in the “Test” directory as thats what i wan’t to be protecting. It contains:

AuthName "Restricted Area"
AuthType Basic
**AuthUserFile /home/a1407273/root/public_html/.htpasswd
**AuthGroupFile /dev/null
require valid-user

Make sure your using the full path to as shown in bold above

The .htpassword is in the “Public_html” folder and that contains the password given to me by the dymanicdrive.com website.

test:qzACNHJ/AqdXg
(Test being the user:and the letters being the hashed password)

thanks for that… I followed your code as an example and i have a question. The code line “AuthUserFile /home/a1407273/root/public_html/.htpasswd” is linked to the public_html folder. In my case, i need to link it to another directory but it is not working. The directory i want to protect is “Teacher Login”. As a code, it looks like this - "public_html/1_7_Teacher-Login. I assume my AuthUserFile code should read - AuthUserFile /home/a9494400/root/public_html/1_7_Teacher-Login/.htpasswd/. is this correct?

It doesn’t matter where the .htpasswd file is for it to work as long as the .htaccess file is linking to the correct .htpasswd file.

Not sure if it matters, but you don’t need the trailing / at the end of .htpasswd - however yes, that should work.

thanks for the help mate… unfortunately, everything you say and everything i try just will not work. I have followed your instructions and instructions from -“http://tools.dynamicdrive.com/password/” yet i still can not get a login box to come up. I dont know if im doing something wrong, or something else is going on, im not sure. thanks again…

No worries, have you tried putting the .htpasswd file in the public_html directory like i have and just link the .htaccess in your teachers directory to that? If that doesn’t work, im not sure what’s going on.

Yes, i linked the htaccess file to the correct htpasswd file. Everything i have done is correct. However, do i need another code for the login prompt box? I.E - Is there another code so a box can come up which allows you to enter your username and password?

No you don’t need any other code, the login box is hard coded into each browser. Not really sure why your’s isn’t working then.

ok firstly sorry if im hijacking any threads !
here is my problem Im trying to create (login and Registration)and some were I have messed things up lol I have made the php files and data base and even try put the code in on my menu1_1.html page but seem to be stuck. dont look good as I work with computers lol anyways would love any help, my site is (www.r1computers.com) if anyone can look an help out were im going wrong

I followed http://www.phpeasystep.com/phptu/6.html (steps)
I think were i maybe going wrong it says Create file main_login.php and use ############### Code

<table width=“300” border=“0” align=“center” cellpadding=“0” cellspacing=“1” bgcolor="#CCCCCC">
<tr>
<form name=“form1” method=“post” action=“checklogin.php”>
<td>
<table width=“100%” border=“0” cellpadding=“3” cellspacing=“1” bgcolor="#FFFFFF">
<tr>
<td colspan=“3”><strong>Member Login </strong></td>
</tr>
<tr>
<td width=“78”>Username</td>
<td width=“6”>:</td>
<td width=“294”><input name=“myusername” type=“text” id=“myusername”></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name=“mypassword” type=“text” id=“mypassword”></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type=“submit” name=“Submit” value=“Login”></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
but then it dont show on my page so i use the code on my page and it shows but no working action ?
So i guess do I need php files ? or do i just type the codes on my .html page

oh and thanks firebirds i tryed
if($username && $Email && $password && password1)
{
but still no joy,Im starting to think maybe i should just give up

umm… this thread is ove 2 years old…

having that said,
take a look at this thread!
http://www.000webhost.com/forum/scripts-code-snippets/26860-basic-register-login-members-only-script.html

Im trying to allow users to login and then after that dislpay there username on my header. Before that i echo out a login form and if there logged in a echo out their username.

on my header

<div id="header">
<div id='status'><?php require('status.php'); ?></div>
<b><a href="index.php">#RealTalk</a></b>
</div>

status.php

<?php

if ($username){
    echo "$username | <a href='logout.php'>Logout</a>";
    
}
else
    echo "<form action='login.php' method='post'>
<table cellspacing='10px'>
    <tr>
		<td>Username:</td>
		<td><input type='text' name='username'><b><a href='register.php'>Register</a></b></td>
	</tr>
	<tr>
		<td>Password:</td>
		<td><input type='password' name='password'><input type='submit' name='loginbtn' value='login' class='button'></td>
	</tr>
	<tr>
		<td></td>
		<td></td>
	</tr>
</table>
</form>";

?>

top of my index page

<?php
session_start();
$username = $_SESSION['username'];
$userid = $_SESSION['userid'];
?>
<html>
<head>
<title><?php echo "$title"; ?> </title>

@Boxmanxyz: try
if (isset($GLOBALS[‘username’])){
echo $GLOBALS[‘username’]."| <a href=‘logout.php’>Logout</a>";

}

Edit: also at the very top of your file, try adding
<?php error_reporting(E_ALL); ?>

First of all i think its supposed to be

error_reporting (E_ALL ^ E_NOTICE);

Because i got an error when i put

error_reporting(E_ALL);

Second of all do you mean put

error_reporting (E_ALL ^ E_NOTICE);

on the top of my index page or the top of my status.php?

i mean
error_reporting(E_ALL);
and i mean on top of both files.
also, what was the error you got with E_ALL ?

It is still not echoing out what i would like it to do. Even after i put that on top om pages!

so, what errors do you get when using E_ALL
?

hello im back. Im now trying to create something similar to a register page, im trying to make an edit profile page. I dont get any errors but every time i press the submit button it acts as if i didnt enter all the required info.

top
if ($user){

require ("connect.php");

$sql = mysql_query("SELECT * FROM Users WHERE id='$userid' ") or die(mysql_error());
$numrows = mysql_num_rows($sql);
if ($numrows == 1){
    
    $row = mysql_fetch_assoc($sql);
    $id = $row['id'];
    $firstname = $row['first_name'];
    $lastname = $row['last_name'];
    $username = $row['username'];
    $email = $row['email'];
    $picture = $row['profile_picture'];
    $about = $row['about_you'];
    $date = $row['date'];
    



}
else
	echo "Sorry, We could not connect to the database!";

$form = "&lt;form action='edit_profile.php' method='post'&gt;
&lt;table&gt;
&lt;tr&gt;
    &lt;td&gt;First Name:&lt;/td&gt;
    &lt;td&gt;&lt;input type='text' name='firstname' class='textbox' value='$firstname'&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;Last Name:&lt;/td&gt;
    &lt;td&gt;&lt;input type='text' name='lastname' class='textbox' value='$lastname'&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;



if ($_POST['savebtn']){
	
	$firstname = fixtext($_POST['firstname']);
    $lastname = fixtext($_POST['lastname']);
    $email = fixtext($_POST['email']);
    $about = fixtext($_POST['about']);
    $password = fixtext($_POST['password']);


	$name = $_FILES['picture'] ['name'];
    $type = $_FILES['picture'] ['type'];
    $size = $_FILES['picture'] ['size'];
    $tmpname = $_FILES['picture'] ['tmp_name'];
    $ext = substr($name, strrpos($name, '.'));

   if ($firstname && $lastname && $email && $password){

	if (strstr($email, "@") && strstr($email, ".") && (strlen($email) &gt;= 6)) {

		$password = md5(md5($password));

		mysql_query("SELECT password FROM Users WHERE id='$userid'");
		$numrows = mysql_num_rows($sql);
		if ($numrows == 1){

		mysql_query("UPDATE Users SET first_name='$firstname' WHERE id='$userid'");

		mysql_query("UPDATE Users SET last_name='$lastname' WHERE id='$userid'");

		mysql_query("UPDATE Users SET email='$email' WHERE id='$userid'");

		mysql_query("UPDATE Users SET about_you='$about' WHERE id='$userid'");

		if ($name){
			$picturename = "$username.$ext";
			move_uploaded_file($tmpname, "pictures/");

			mysql_query("UPDATE Users SET profile_picture='$picturename' WHERE id='$userid'");

		}

		echo "Your account in

echoes

}
			else
				echo "Your password was incorrect! $form";


		
    }
		else
			echo "You did not enter a valid email! $form";
	
    }
    else
    	echo "You did not fill out all required fields! $form";

}
else
	echo "$form";

	///////////////////////////////////////////////////////////////////////////////////////////////////////////////



	$passform = "&lt;form action='edit_profile.php' method='post'&gt;
&lt;table cellspac