allora ho 3 file.
il primo e' account.php e il codice è questo:
<?
include_once("functions.inc.php");
if ($_REQUEST["action"] != "signup" && $_REQUEST["action"] != "confirm") {
signupForm();
}
if ($_REQUEST["action"] == "signup") {
$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];
createAccount($username,$password,$email);
}
if ($_REQUEST["action"] == "confirm" && $_REQUEST["confirm"] != "") {
confirm($_REQUEST["confirm"]);
}
?>
---------------------------------------------------------------------
il secondo file e' config.inc.php e il codice e' questo:
<?php
# Database name
$db = "bla bla";
# Internet address or hostname of database host
$db_host = "bla bla";
# Database username
$db_user = "bla bla";
# Database password
$db_password = "bla bla";
?>
----------------------------------------------
e l'ultimo file e' functions.inc.php e il codice e' questo:
<?php
include_once("config.inc.php");
function confirm ($random) {
# Inherit database connection information from variables defined in config.inc.php
global $db, $db_host, $db_user, $db_password;
# Connect to the database and report any errors on connect.
$cid = mysql_connect($db_host,$db_user,$db_password);
if (!$cid) {
die("ERROR: " . mysql_error() . "\n");
}
# Setup SQL statement, update account to show that user has confirmed.
$SQL = "UPDATE account SET confirmed = '0' WHERE random = '$confirm'";
$result = mysql_db_query($db,$SQL,$cid);
# Check for errors.
if (!$result) {
die("ERROR: " . mysql_error() . "\n");
} else {
echo "Congratulations, your account has been confirmed successfully. You may now login.";
}
mysql_close($cid);
}
function signupForm () {
# Nothing more than spitting out HTML for the form
echo "<form name=\"signup\" method=\"POST\" action=\"?action=signup\">";
echo "Username: <input type=\"text\" name=\"username\">
";
echo "Password: <input type=\"password\" name=\"password\">
";
echo "E-Mail: <input type=\"text\" name=\"email\">
";
echo "<input type=\"submit\"></form>";
}
function createAccount ($username, $password, $email) {
if ($username == "" || $password == "" || $email == "") {
die("ERROR: Please make sure that all entries are valid!");
}
# Inherit database connection information from variables defined in config.inc.php
global $db, $db_host, $db_user, $db_password;
# Connect to the database and report any errors on connect.
$cid = mysql_connect($db_host,$db_user,$db_password);
if (!$cid) {
die("ERROR: " . mysql_error() . "\n");
}
# Create Random number
$floor = 100000;
$ceiling = 999999;
srand((double)microtime()*1000000);
$random = rand($floor, $ceiling);
# Message sent in the e-mail to the user that's signing up.
$message = "You or someone using your email address has requested an account on the system. If you requested the account please click on the confirmation link below. If not, please send a message to accounts@wherever.com.\n\nhttp://somewhere.com/account.php?action=confirm&confirm=$random\n\nThan ks!";
# Send the confirmation e-mail to the user.
mail($email, "Account Confirmation", $message);
# I usually hash the passwords instead of storing the plaintext password in the database.
# Just comment the next line out if you'd prefer to store them as plaintext.
$password = md5($password);
# Setup SQL statement and add the account into the system.
$SQL = "INSERT INTO account VALUES ('$username','$password','$email','1','$random')";
$result = mysql_db_query($db,$SQL,$cid);
# Check for errors.
if (!$result) {
die("ERROR: " . mysql_error() . "\n");
} else {
echo "Congratulations, your account has been added into the system. Check your e-mail for the confirmation message";
}
mysql_close($cid);
}
?>
-----------------------------------------------------------------------------
Questa e solo la parte per la registrazione. Io vorrei che ad esempio, cliccando di nuovo sul pulsante contatti non mi esce di nuovo il form per la registrazione, ma dovrebbe uscirmi il form per il login. Solo che non so da dove iniziare. Mi daresti un aiutino? Grazie


Rispondi quotando