Edit constants.php (add one constant):
Edit the register() function in session.php:
That's just the code from the login() function pasted into the register() function before returning 0.
Edit register.php:
That's it.
- Code:
<$php
/**
* Auto Login - this constant determines whether
* or not to login a new user at the time of
* registration.
*/
define("AUTO_LOGIN", true);
Edit the register() function in session.php:
- Code:
<$php
/**
* register - Gets called when the user has just submitted the
* registration form. Determines if there were any errors with
* the entry fields, if so, it records the errors and redirects
* the user to the form. If none, it attempts to register
* the new user.
*/
function register($subuser, $subpass, $subemail){
global $database, $form, $mailer; //The database, form and mailer object
...
/* No errors, add the new account to the */
else{
if($database->addNewUser($subuser, md5($subpass), $subemail)){
if(EMAIL_WELCOME){
$mailer->sendWelcome($subuser,$subemail,$subpass);
}
/*** This is new ************************/
if(AUTO_LOGIN){
/* Username and password correct, register session variables */
$this->userinfo = $database->getUserInfo($subuser);
$this->username = $_SESSION['username'] = $this->userinfo['username'];
$this->userid = $_SESSION['userid'] = $this->generateRandID();
$this->userlevel = $this->userinfo['userlevel'];
/* Insert userid into database and update active users table */
$database->updateUserField($this->username, "userid", $this->userid);
$database->addActiveUser($this->username, $this->time);
$database->removeActiveGuest($_SERVER['REMOTE_ADDR']);
}
/*** End of new code ************************/
return 0; //New user added succesfully
}else{
return 2; //Registration attempt failed
}
}
That's just the code from the login() function pasted into the register() function before returning 0.
Edit register.php:
- Code:
<$php
/**
* The user is already logged in, not allowed to register.
*/
if($session->logged_in && !isset($_SESSION['regsuccess'])){ /*** This is new **********/
echo "<h1>Registered</h1>";
echo "<p>We're sorry <b>$session->username</b>, but you've already registered. "
."<a href=\"main.php\">Main</a>.</p>";
}
/**
* The user has submitted the registration form and the
* results have been processed.
*/
else if(isset($_SESSION['regsuccess'])){
/* Registration was successful */
if($_SESSION['regsuccess']){
echo "<h1>Registered!</h1>";
echo "<p>Thank you <b>".$_SESSION['reguname']."</b>, your information has been added to the database, "
."you are now logged in. <a href=\"main.php\">Main</a>.</p>"; /*** This is new **************/
}
That's it.