Escolar Documentos
Profissional Documentos
Cultura Documentos
First we'll create an include file for the connection info, which will save us from having it
separately in each script. Paste the following into a file called "config.php"
<?php
$server = "localhost"; // server to connect to.
$database = "mydata"; // the name of the database.
$db_user = "myusername"; // mysql username to access the database with.
$db_pass = "mypassword"; // mysql password to access the database with.
$table = "users"; // the table that this script will set up and use.
?>
You'll need to create the user table on your database to store the info in. To do so, paste the
following into a file called "create.php". Then upload both create.php and config.php, and
point your browser to create.php.
<?php
include ("config.php");
mysql_query($create)
or die ("Could not create tables because ".mysql_error());
echo "Complete.";
?>
Now you'll need to create your user signup form. This can be a regular HTML page that
simply points to your PHP script. It should look like this:
<html><head>
<title>User Registration</title>
</head><body>
<form action="register.php" method="post">
Then, create a file called register.php, or whatever you pointed the form to, and put this
code in it:
<?php
include("config.php");
?>
Now the log-in page, another HTML page pointing to another PHP script:
<html><head>
<title>User Registration</title>
</head><body>
</body></html>
The log-in script that the above form points to:
<?php
include("config.php");
$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows <= 0) {
echo "Sorry, there is no username $username with the specified password.<br>";
echo "<a href=login.html>Try again</a>";
exit;
} else {
The check cookie function on all pages in the member's area, to make sure they're logged
in:
And finally, the log out script, which can just be pointed to with a regular link:
<?php
// expire cookie
setcookie ("loggedin", "", time() - 3600);
?>