- Home
- Categorie
- Coding e Sistemistica
- PHP
- Creazione account php
-
Creazione account php
Salve ragazzi
Ho uno script php che mi permette di creare account.
Avendo creato una tabella mysql e inserendo mon password ed email mi crea l'account e basta; ora come posso creare il resto?
Cioe'
ho questi file:
**account.php
**[PHP] 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"]);
}[/PHP]
**config.php
**[PHP]# Database name
$db = "xxx";Internet address or hostname of database host
$db_host = "localhost";
Database username
$db_user = "xxx";
Database password
$db_password = "xxx";[/PHP]
**functions.php
**[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"><br>";
echo "Password: <input type="password" name="password"><br>";
echo "E-Mail: <input type="text" name="email"><br>";
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 email.\n\nhttp://www.miosito/account/account.php?action=confirm&confirm=$random\n\nThanks!";
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);
}[/PHP]
cioe' devo creare il login e la pag utente.
Mi aiutate?