Hi is there ant generour people out there that can help me make a login script in php. I have made one in .ASP before but i couldnt get the db to work properly so i tohught i would try php as somebody told me it ouwld be easier to host for free and stuff so cna sum one put me on track plz....
Login Script!!!!!
Have you searched for tutorials on the subject? There are a ton available.
i ahve but when i get them they are either useless or dont go into full details such as registration pages and linking it up to a database.
i ahve but when i get them they are either useless
this won't help u and us...
Try http://www.etronicscomputers.com/docs/phpforbeginners.htm
provides a good tutorial on settng up a login script
thnx for tht 1 but i tried it and i got this error
Warning: Cannot add header information - headers already sent by (output started at /home/virtual/site52/fst/home/talkster5/public_html/login/login.php:1) in /home/virtual/site52/fst/home/talkster5/public_html/login/login.php on line 12
any ideas
but nayway i wanted one with a registration part aswell
That error can be caused my a number of things. It basically means that something has written to the browser before the headers which the cookie information would have been sent in. I beleive these are about the very first thing that get's sent (but I might be wrong).
One of my most annoying occurances of this error was when I had a blank line at the top of one of my files before the "<?php" began. This meant that one blank line was sent to the client before and commands were executed that needed to send headders, thus when it got to sending the headders, it was too late.
Things to look for:
- Blank lines outside the "<?php" and "?>"
- Anything that writes to the client, placed before header or session handelers.
Based on what I saw on the site suggested earlier in this thread, I would imagine that you've probably got a blank line before the "<?php". If you do, try removing that.
Everything I've said here is based on "assumptions+experience(+ a little reading)" so please correct me if there is anything I've said that isn't quite accurate.
Hope this helps
thnx i have gone back to .asp its much better for logins than php
I doubt it, it is just that your current knowledge of PHP and skill at implementing what you want in PHP hasnt reached a high enough level yet.
ok ill keep on going with this just reply to me on my other post plz
I remember having a similar problem i searched around and found the code i used and it works. i hope it helps.
//login.html
<html>
<head>
<title>Login</title>
</head>
<body>
<form method="POST" action="login.php">
Username: <input type="text" name="username" size="20">
Password: <input type="password" name="password" size="20">
<input type="submit" value="Login" name="login">
</form>
</body>
</html>
//login.php code
<?
if (!isset($POST['username']) || !isset($POST['password']))
{
header("Location: login.htm");
}
elseif (empty($POST['username']) || empty($POST['password']))
{
header("Location: login.htm");
}
else
{
$user = addslashes($_POST['username']);
$pass = md5($_POST['password']);
$DBhost = "localhost";
$DBuser = "username";
$DBpass = "password";
$DBName = "dbname";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
@mysql_select_db("$DBName") or die("Unable to select
database $DBName");
$sqlquery = "SELECT * FROM users WHERE username='$user' AND password='$pass'";
$result = mysql_query($sqlquery);
//mysql_close();
$rowCheck = mysql_num_rows($result);
if($rowCheck > 0)
{
while($row = mysql_fetch_array($result))
{
session_start();
session_register('username');
//echo 'You have successfully logged in';
header("Location: checkLogin.php");
}
}
else
{
echo 'Login Failed';
}
}
?>
//checklogin.php check that your logged in
<?
session_start();
if(session_is_registered('username'))
{
echo'Welcome you are still logged in';
}
else
{
header("Location: http://localhost/login.htm");
}
?>
//logout.php logout code
<?
session_start();
if(session_is_registered('username'))
{
session_unset();
session_destroy();
echo'You are now logged out of the system';
}
else
{
header("Location: http://localhost/login.htm");
}
?>
if you have any probs give me a shout and ill see if i can help but it works for me.
very interesting im just wondering how do you register users? and would it direct users to index.php or .html
just have a simple form with
username and password fields which post data to a adduser.php or somethign like that which uses a insert statemet such as
INSERT INTO users (username, password) VALUES ('$user', '$password');
does that answer your question?
not sure exactly what you mean by direct users to indes.html or php if you mean to add user to db then to .php but if you mean once u have logged in it can be either it does not matter
Hey,
I was in the same place you were... i needed a login script for a database that i aloready had put up to MySQL via PHPMyadmin... the login script above seems just like mine... i just authenticate the password against a pre-existing member number and their lastname against their lastname...
it took me about 4 weeks of searhcing these boards and forums and so on...
if you just can't figure it out lemme know... i'll help you with the code if i can...
Jon
ive dun my scipt now with a registration page jsut returning a few error when i try to register
Forbidden
You don't have permission to access /< on this server.
Apache/1.3.26 Server at localhost Port 80
ive dun my scipt now with a registration page jsut returning a few error when i try to register
Forbidden
You don't have permission to access /< on this server.
Apache/1.3.26 Server at localhost Port 80
Does it say what line of code is incorrect? post your code so we can check it out...
what cide do u want teh registration form cause tht is wen the error comes
Give me the reg form if that is where the error comes in... i'm having trouble though reading your posts becuas of spelling though so i think i understand...
sorry just me typing fast i know about my spelling