TommyN14
asked on
Create a login page in php
Hi,
I'm new to php and mysql. How do I create a login page? Please help with same codes.
Thanks!
I'm new to php and mysql. How do I create a login page? Please help with same codes.
Thanks!
Hi,
these might help:-
http://llimllib.f2o.org/LoginTutorial.html
http://www.plus2net.com/php_tutorial/php_login_script.php
and there's some good tutorials here:-
http://www.phpfreaks.com/
Dbb
these might help:-
http://llimllib.f2o.org/LoginTutorial.html
http://www.plus2net.com/php_tutorial/php_login_script.php
and there's some good tutorials here:-
http://www.phpfreaks.com/
Dbb
ASKER
Hi,
Sorry for getting back so late. Right now I'm having a problem that when I type in the username & pwd and click on Login, the page refresh itself...I checked the view source of the page and found out that the action attribute of the form tag is empty. Here's the form tag: <form action="<?$PHP_SELF?>" method="post">. What's wrong with it?
Thanks!
Sorry for getting back so late. Right now I'm having a problem that when I type in the username & pwd and click on Login, the page refresh itself...I checked the view source of the page and found out that the action attribute of the form tag is empty. Here's the form tag: <form action="<?$PHP_SELF?>" method="post">. What's wrong with it?
Thanks!
<form action="<? echo $PHP_SELF; ?>" method="post">
Hi,
are you using the same page to handle the form or do you have a different page with the handling script on it?
If you're using the same page (script is on the same page as login): -
<form action="<?php echo $PHP_SELF; ?>" method="post">
or if you are using a seperate script file:-
<form action="/myscript.php" method="post">
Dbb
are you using the same page to handle the form or do you have a different page with the handling script on it?
If you're using the same page (script is on the same page as login): -
<form action="<?php echo $PHP_SELF; ?>" method="post">
or if you are using a seperate script file:-
<form action="/myscript.php" method="post">
Dbb
ASKER
Hi,
I got this test code from one of the website, and try to test it out...When I click on Login, the page refresh itself and clear the data in the text boxes. Any ideas?
Thanks!
<?php
//if they haven't pressed the submit button, then show the form
if(!$submit)
{
?>
<html>
<head>
<title>My Login Form</title>
</head>
<body>
<form action="<? echo $_SERVER['PHP_SELF']?>" method="post">
<div>
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="submit" value="Login" /><br />
</div>
</form>
</body>
</html>
<?php
}
else //otherwise, let's process this stuff
{
if($username == "user" && $password == "mypass") //if they got it right, let's go on
{
session_start();
session_register("mysessio nvariable" ); //set a variable for use later
$id = session_id(); //let's grab the session ID for those who don't have cookies
$url = "Location: page2.php?sid=" . $id;
header($url);
}
else //they got something wrong and we should tell them
{
?>
<html>
<head>
<title>My Login Form</title>
</head>
<body>
<span style="color:#ff0000;">Pas sword/User name Is Invalid</span><br />
<form action="<? echo $_SERVER['PHP_SELF']?>" method="post">
<div>
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="submit" value="Login" /><br />
</div>
</form>
</body>
</html>
<?php
}
}
?>
I got this test code from one of the website, and try to test it out...When I click on Login, the page refresh itself and clear the data in the text boxes. Any ideas?
Thanks!
<?php
//if they haven't pressed the submit button, then show the form
if(!$submit)
{
?>
<html>
<head>
<title>My Login Form</title>
</head>
<body>
<form action="<? echo $_SERVER['PHP_SELF']?>" method="post">
<div>
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="submit" value="Login" /><br />
</div>
</form>
</body>
</html>
<?php
}
else //otherwise, let's process this stuff
{
if($username == "user" && $password == "mypass") //if they got it right, let's go on
{
session_start();
session_register("mysessio
$id = session_id(); //let's grab the session ID for those who don't have cookies
$url = "Location: page2.php?sid=" . $id;
header($url);
}
else //they got something wrong and we should tell them
{
?>
<html>
<head>
<title>My Login Form</title>
</head>
<body>
<span style="color:#ff0000;">Pas
<form action="<? echo $_SERVER['PHP_SELF']?>" method="post">
<div>
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="submit" value="Login" /><br />
</div>
</form>
</body>
</html>
<?php
}
}
?>
Hi,
try <?php echo $_SERVER['PHP_SELF']?> instead of <? echo $_SERVER['PHP_SELF']?>
Dbb
try <?php echo $_SERVER['PHP_SELF']?> instead of <? echo $_SERVER['PHP_SELF']?>
Dbb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry for taking so long to accept this answer. I was on another project. Got sidetrack.
Thank you!
Thank you!
there is username: test and password:test123 in mysql database. php would be something like this
<?
mysql_connect("hostname", "username", "pass") or die("ERROR: Connection failed!");
mysql_select_db("users") or die("ERROR: Database not selected!");
$res=mysql_query("SELECT * FROM users WHERE user='".$_POST["username"]
if (mysql_num_rows($res)>0) { ...redirect to the logged in page... }
else { echo "ERROR: Username and/or password incorrect. Please try again!"; }
?>
that would be the simple login script. You would need a form with text fields named username and password that will have action set to the file shown up there.
Hope I helped...