ciao ragazzi dovrei fare delle piccoli cambiamenti, quando un utente si registra lo porta nella home del sito senza un link di attivazione
questo è il form del mio sito in html
questo è per registrarsi fatto in phpcodice HTML:<form action="" method="POST" autocomplete="off"> {$registerMsg} <input type="text" id="short" name="username" placeholder="{$lng->username}" /> <input type="password" id="short" name="password" placeholder="{$lng->password}" /> <input type="text" id="short" name="email" placeholder="{$lng->email}" /> {$captcha} <button type="submit" name="register" class="register-button">{$lng->register}</button> </form>
il file è chiamato "welcome.php
questo qui è nel classes.php del mio sito per registrarsiCodice PHP:
function PageMain() { global $TMPL, $LNG, $CONF, $db, $loggedIn, $settings; if($settings['captcha']) { $TMPL['captcha'] = '<input type="text" name="captcha" placeholder="'.$LNG['captcha'].'" /> <span class="welcome-captcha"><img src="'.$CONF['url'].'/includes/captcha.php" /></span>'; } if(isset($_POST['register'])) { // Register usage $reg = new register(); $reg->db = $db; $reg->url = $CONF['url']; $reg->username = $_POST['username']; $reg->password = $_POST['password']; $reg->email = $_POST['email']; $reg->captcha = $_POST['captcha']; $reg->captcha_on = $settings['captcha']; $reg->message_privacy = $settings['mprivacy']; $reg->like_notification = $settings['notificationl']; $reg->comment_notification = $settings['notificationc']; $reg->shared_notification = $settings['notifications']; $reg->chat_notification = $settings['notificationd']; $reg->friend_notification = $settings['notificationf']; $reg->verified = $settings['verified']; $reg->email_like = $settings['email_like']; $reg->email_comment = $settings['email_comment']; $reg->email_new_friend = $settings['email_new_friend']; $reg->sound_new_notification = $settings['sound_new_notification']; $reg->sound_new_chat = $settings['sound_new_chat']; $TMPL['registerMsg'] = $reg->process();
if($TMPL['registerMsg'] == 1) { if($settings['mail']) { sendMail($_POST['email'], sprintf($LNG['welcome_mail'], $settings['title']), sprintf($LNG['user_created'], $settings['title'], $_POST['username'], $_POST['password'], $CONF['url'], $settings['title']), $CONF['email']); } header("Location: ".$CONF['url']."/index.php?a=feed"); } }
Codice PHP:
class register { public $db; public $url; public $username; public $password; public $email; public $captcha; public $captcha_on; public $message_privacy; public $verified; public $like_notification; public $comment_notification; public $shared_notification; public $chat_notification; public $friend_notification; public $email_like; public $email_comment; public $email_new_friend; public $sound_new_notification; public $sound_new_chat; function process() { global $LNG;
$arr = $this->validate_values(); // Must be stored in a variable before executing an empty condition if(empty($arr)) { // If there is no error message then execute the query; $this->query(); // Set a session and log-in the user $_SESSION['username'] = $this->username; $_SESSION['password'] = md5($this->password); //Redirect the user to his personal profile //header("Location: ".$this->url."/something"); // Return (int) 1 if everything was validated $x = 1; // return $LNG['user_success']; } else { // If there is an error message foreach($arr as $err) { return notificationBox('transparent', $LNG['error'], $LNG["$err"], 1); // Return the error value for translation file } } return $x; } function verify_if_user_exist() { $query = sprintf("SELECT `username` FROM `users` WHERE `username` = '%s'", $this->db->real_escape_string(strtolower($this->username))); $result = $this->db->query($query); return ($result->num_rows == 0) ? 0 : 1; } function verify_if_email_exists() { $query = sprintf("SELECT `email` FROM `users` WHERE `email` = '%s'", $this->db->real_escape_string(strtolower($this->email))); $result = $this->db->query($query); return ($result->num_rows == 0) ? 0 : 1; } function verify_captcha() { if($this->captcha_on) { if($this->captcha == "{$_SESSION['captcha']}" && !empty($this->captcha)) { return true; } else { return false; } } else { return true; } }
il problema è che devo mettere questi piccoli codici nel sito e non so dove inserirli
come posso fare ragazzi, al posto di NewUser e AddUser dovrei mettere il nome "register o username" oppure va bene così? grazie se mi aiutate sto impazzendoCodice PHP:
<?php
class NewUser
{
public $conn;
public function AddUser()
{
$this->ErrorReport();
}
protected function DbConnect()
{
include "db_config.php";
$this->conn = mysql_connect($host,$user,$password) OR die("Impossibile connettersi al database");
mysql_select_db($db, $this->conn);
}
protected function IsEmptyField()
{
if(empty($_POST['username']) OR empty($_POST['email']) OR empty($_POST['password']))
{
return TRUE;
}
else
{
return FALSE;
}
}
protected function VerifyPassword()
{
if($_POST['password'] == $_POST['password2'])
{
return TRUE;
}
else
{
return FALSE;
}
}
protected function UsernameExists()
{
$this->DbConnect();
$sql = "SELECT username FROM users WHERE username='$_POST[username]'";
$res = mysql_query($sql, $this->conn);
if($row = mysql_fetch_array($res))
{
mysql_close($this->conn);
return TRUE;
}
else
{
mysql_close($this->conn);
return FALSE;
}
}
protected function EmailExists()
{
$this->DbConnect();
$sql = "SELECT * FROM users WHERE email='$_POST[email]'";
$res = mysql_query($sql, $this->conn);
if($row = mysql_fetch_array($res))
{
mysql_close($this->conn);
return TRUE;
}
else
{
mysql_close($this->conn);
return FALSE;
}
}
protected function VerifyEmail()
{
$pattern = "^([a-zA-Z0-9])+([a-zA-Z0-9]+[-_\.]?)*([a-zA-Z0-9])+(@)([a-zA-Z0-9])+([a-zA-Z0-9]+[-_\.]?)*([a-zA-Z0-9])+(\.[a-z]{2,4})$";
if(ereg($pattern,$_POST['email']))
{
return TRUE;
}
else
{
return FALSE;
}
}
public function ErrorResult($num)
{
header("Location: form.php?alert=" . $num);
die;
}
protected function ErrorReport()
{
if($this->IsEmptyField())
{
$this->ErrorResult(1);
}
if(!$this->VerifyPassword())
{
$this->ErrorResult(2);
}
if($this->UsernameExists())
{
$this->ErrorResult(3);
}
if($this->EmailExists())
{
$this->ErrorResult(4);
}
if(!$this->VerifyEmail())
{
$this->ErrorResult(5);
}
$this->InsertNewUser();
}
protected function GetKey()
{
$car = "aAbBcCdDeEfFgGhHiIlLjJkKmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789";
$dim = 40;
srand((double)microtime()*1000000);
$string = '' ;
for($inc=0; $inc<$dim; $inc++)
{
$rand = rand(0, strlen($car)-1);
$scar = substr($car, $rand, 1);
$string = $string . $scar;
}
return $string;
}
protected function SendUserMail($key)
{
$content = "Benvenuto $_POST[username],\r\n";
$content .= "per confermare la tua iscrizione devi cliccare sul seguente link:\r\n\r\n";
$content .= "http://www.itworldlive.it/prova/prova/verify_user.php?key=" . $key;
mail($_POST['email'], "Iscrizione al sito...", $content, "From: Benvenuto su World Live <simone_cardillo@hotmail.it>");
return;
}
protected function InsertNewUser()
{
$password = md5($_POST['password']);
$key_control = $this->GetKey();
$sql = "INSERT INTO users (username,email,password,key_control) VALUES ('$_POST[username]','$_POST[email]','$password','$key_control')";
$this->DbConnect();
mysql_query($sql,$this->conn);
mysql_close($this->conn);
$this->SendUserMail($key_control);
}
public function VerifyUser()
{
$sql = "SELECT id FROM users WHERE key_control='$_GET[key]'";
$this->DbConnect();
$res = mysql_query($sql,$this->conn);
if($row = mysql_fetch_array($res))
{
$query = "UPDATE users SET ver=1,key_control='0' WHERE id='$row[id]'";
mysql_query($query,$this->conn);
mysql_close($this->conn);
header("location: http://www.itworldlive.it");
echo "Il tuo account è ora attivato!";
}
else
{
echo "Impossibile verificare l'account!";
}
}
}
?>