i have a problem ...
i have already create a login page that connected to the database mysql, and it's work..
i can login and jump to the another page, but i still have a little problem that i don't know
if i login that my username and password only use one time i mean only one page
how to make that when i login using my username and password i can use the information of the username and password without i must login again, that i read a book using the cookies..
but i still confuse.... maybe the sample is like forum discussion, i login first and than i can write my message using the user and password that in the first page i login..
how make the username and pass like that ??
i confuse, please help me
thank's
how to make user login ?
You have to use cookies.
like this:
<?
// check if the form has been submitted.
if (isset($submit))
{
// a includefile which connect to mysql
require 'db_connection.inc';
$check_user_and_pass = mysql_query("
select * user_properties where
username = '$user' and password = '$pass'");
if (mysql_num_rows($check_user_and_pass) > 0)
{
// set a cookie, containing the user var
setcookie("user", $user);
}
header("Location: memberarea.php");
}
?>
<body>
<form method="post" action="<? echo ($PHP_SELF); ?>">
Username:
<input type="text" name="user"><br>
Password:
<input type="password" name="pass"><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
then on each of page of the memberarea you have to check for a $user var,
to se if a cookie is set or not. if not, send the user to the loginform again...
You can also use session. For more info you can check out http://www.php.net/manual/en/function.session-start.php
Also check out Juli Meloni's sample code on user authentication at http://www.thickbook.com/
Hope this helps.
Laura Brandt
--
Aletia Hosting - Full-Featured, Superfast Web Hosting
PHP, MySQL, Perl, Multiple domain support and more.
200MB + 10GB Transfer at $9.95/mth
http://AletiaHosting.com - AIM: AletiaCorp
Email: sales@aletia.net
oke thank's i will try it first
Shiny wrote:
You have to use cookies.
like this:
<?
// check if the form has been submitted.
if (isset($submit))
{
// a includefile which connect to mysql
require 'db_connection.inc';
$check_user_and_pass = mysql_query("
select * user_properties where
username = '$user' and password = '$pass'");
if (mysql_num_rows($check_user_and_pass) > 0)
{
// set a cookie, containing the user var
setcookie("user", $user);
}
header("Location: memberarea.php");
}
?>
<body>
<form method="post" action="<? echo ($PHP_SELF); ?>">
Username:
<input type="text" name="user">
Password:
<input type="password" name="pass">
<input type="submit" name="submit" value="submit">
</form>
</body>
then on each of page of the memberarea you have to check for a $user var,
to se if a cookie is set or not. if not, send the user to the loginform again...
Code not work:
Warning: Cannot add header information - headers already sent by (output started at /home/stud/dmihaiu/public_html/cws/admin/login.php:17) in /home/stud/dmihaiu/public_html/cws/admin/login.php on line 18