Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
Php Auto login after register
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Weasel" data-source="post: 181862" data-attributes="member: 9520"><p>First of all, this looked horrible, so I re-wrote your log-in script:</p><p>[PHP]if (isset($_POST['email']) && isset($_POST['password']))</p><p>{</p><p>$email = $_POST['email'];</p><p>$password = $_POST['password'];</p><p>}</p><p>if (empty($email) || empty($password))</p><p>{</p><p>$errors[] = 'Please enter your valid email and password';</p><p>}</p><p>else if (user_exists($email) === false)</p><p>{</p><p>$errors[] = 'Our records cannot find this email. Are you sure you have registered?';</p><p>} </p><p> </p><p>else</p><p>{</p><p>if (login($email, $password) === false) {</p><p>$errors[] = "This email/password combination is incorrect";</p><p>}</p><p>else</p><p>{</p><p>$_SESSION['id'] = login($email, $password);</p><p>mysql_query("UPDATE usersystem SET online = '1' WHERE id = '".$_SESSION['id']."'");</p><p>header('Location: ?ref=profile');</p><p>}</p><p>}</p><p> </p><p>if (!empty($errors))</p><p>{</p><p>echo output_errors($errors);</p><p>}[/PHP]</p><p> </p><p>Same for your register:</p><p>[PHP]<?php</p><p>if (!empty($_POST))</p><p>{</p><p> $required_fields = array ('email', 'username', 'password', 'password_again', 'first_name', 'last_name');</p><p> foreach ($_POST as $key => $value)</p><p>{</p><p> if (empty($value) && in_array($key, $required_fields))</p><p>{</p><p> $errors[] = 'ALL fields MUST be filled out correctly';</p><p> break 1;</p><p> }</p><p> }</p><p> </p><p>if (empty($errors))</p><p>{</p><p>if (user_exists($_POST['email']) === true)</p><p>{</p><p>$errors [] = 'Sorry, the email \'' . $_POST['email'] . '\' is already in use.'; </p><p>}</p><p>if (preg_match("/\\s/", $_POST['email']) == true)</p><p>{</p><p>$errors[] = 'Your email must not contain any spaces';</p><p>}</p><p>if (user_exists($_POST['username']) === true)</p><p>{</p><p>$errors [] = 'Sorry, the username \'' . $_POST['username'] . '\' is already in use.'; </p><p>}</p><p>if (preg_match("/\\s/", $_POST['username']) === true)</p><p>{</p><p>$errors[] = 'Your username must not contain any spaces';</p><p>}</p><p>if (strlen($_POST['password']) < 6)</p><p>{</p><p>$errors[] = 'Your password must be in between 6-24 characters long';</p><p>}</p><p>if ($_POST['password'] !== $_POST ['password_again'])</p><p>{</p><p>$errors[] = 'Your passwords did not match';</p><p>}</p><p>}</p><p>} </p><p>?>[/PHP]</p><p> </p><p>However, like ecko said, where is the part where you insert the user into the database? I can't do much without that.</p></blockquote><p></p>
[QUOTE="Weasel, post: 181862, member: 9520"] First of all, this looked horrible, so I re-wrote your log-in script: [PHP]if (isset($_POST['email']) && isset($_POST['password'])) { $email = $_POST['email']; $password = $_POST['password']; } if (empty($email) || empty($password)) { $errors[] = 'Please enter your valid email and password'; } else if (user_exists($email) === false) { $errors[] = 'Our records cannot find this email. Are you sure you have registered?'; } else { if (login($email, $password) === false) { $errors[] = "This email/password combination is incorrect"; } else { $_SESSION['id'] = login($email, $password); mysql_query("UPDATE usersystem SET online = '1' WHERE id = '".$_SESSION['id']."'"); header('Location: ?ref=profile'); } } if (!empty($errors)) { echo output_errors($errors); }[/PHP] Same for your register: [PHP]<?php if (!empty($_POST)) { $required_fields = array ('email', 'username', 'password', 'password_again', 'first_name', 'last_name'); foreach ($_POST as $key => $value) { if (empty($value) && in_array($key, $required_fields)) { $errors[] = 'ALL fields MUST be filled out correctly'; break 1; } } if (empty($errors)) { if (user_exists($_POST['email']) === true) { $errors [] = 'Sorry, the email \'' . $_POST['email'] . '\' is already in use.'; } if (preg_match("/\\s/", $_POST['email']) == true) { $errors[] = 'Your email must not contain any spaces'; } if (user_exists($_POST['username']) === true) { $errors [] = 'Sorry, the username \'' . $_POST['username'] . '\' is already in use.'; } if (preg_match("/\\s/", $_POST['username']) === true) { $errors[] = 'Your username must not contain any spaces'; } if (strlen($_POST['password']) < 6) { $errors[] = 'Your password must be in between 6-24 characters long'; } if ($_POST['password'] !== $_POST ['password_again']) { $errors[] = 'Your passwords did not match'; } } } ?>[/PHP] However, like ecko said, where is the part where you insert the user into the database? I can't do much without that. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
Php Auto login after register
Top