Results 1 to 4 of 4
-
2nd Aug 2012, 10:11 AM #1OPMember
PHP PDO login system, user class. Also Includes a theming system {Source}
Hello,
Before you look at the source I would like to say a huge thank you to Bennett's (http://btreptow.com/) who is one of my developer/beta tester for Graft Development. He has imputed allot of his own work into script, and i cannot take credit for the input he has put into this himself. Secondly I would like to thank Brad for help testing the script at each stage.
config.inc.php
PHP Code:<?php
define("MYSQL_HOST","localhost");
define("MYSQL_USER","username");
define("MYSQL_PASSWORD","password");
define("MYSQL_DATABASE","db_name");
define("CURRENT_DESIGN","default");
try {
$dbh = new PDO("mysql:host="MYSQL_HOST.";dbname=".MYSQL_DATABASE,MYSQL_USER,MYSQL_PASSWORD);
} catch(PDOException $e){
echo $e->getMessage();
}
?>
PHP Code:<?php
class user {
public $uid = "";
public $userinfo;
public function __construct($id = null)
{
if(null !== $id)
{
$this->getUserInfo($id);
$this->uid = $id;
}
}
public function __destruct(){
}
public function getUserInfo($id){
global $dbh;
$st = $dbh->prepare("SELECT * FROM `users` WHERE `id` = :id LIMIT 1");
$st->execute(array(":id" => $id));
$this->userinfo = $st->fetch(PDO::FETCH_OBJ);
}
public function login($email,$password){
global $dbh;
$st = $dbh->prepare("SELECT * FROM `users` WHERE `email` = :email AND `password` = :password LIMIT 1");
$st->execute(array(":email" => $email,":password" => $password));
$result = $st->fetch(PDO::FETCH_OBJ);
if ($result > 0) {
$id = $result->id;
$this->uid = $id;
return $id;
}
else {
return "Login error";
}
}
public function signup($fname,$lname,$email,$password,$ip){
global $dbh;
$st = $dbh->prepare("SELECT count(*) FROM `users` WHERE `email` = :email LIMIT 1");
$st->execute(array(":email" => $email));
$Data = $st->fetchColumn();
if ($Data > 0) {
return "Error on email";
} else {
try {
$st = $dbh->prepare("INSERT INTO users (email, password, firstname, lastname, ip) value (:email, :password, :firstname, :lastname, :ip)");
$st->execute(array(":email" => $email, ":password" => $password, ":firstname" => $fname, ":lastname" => $lname, ":ip" => $ip));
} catch (PDOException $err) {
return "Error " . $err->getMessage();
}
$st = $dbh->prepare("SELECT * FROM `users` WHERE `email` = :email AND `password` = :password LIMIT 1");
$st->execute(array(":email" => $email,":password" => $password));
$result = $st->fetch(PDO::FETCH_OBJ);
if ($result > 0) {
$id = $result->id;
$this->uid = $id;
return $id;
}
}
}
}
?>
PHP Code:<?php
session_start();
include("include/config.inc.php");
include("include/classes/user.inc.php");
if (isset($_POST['submit'])) {
$fname = htmlentities($_POST['fname']);
$lname = htmlentities($_POST['lname']);
$email = $_POST['email'];
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error = "This email address is not valid, sorry. Alternative this field could been left blank.";
} Else {
if(!filter_var($fname, FILTER_SANITIZE_STRIPPED)) {
$error = "This first name has been blocked by our filter, you cannot use miscellaneous characters. Alternative this field could been left blank.";
} Else {
if(!filter_var($lname, FILTER_SANITIZE_STRIPPED)) {
$error = "This last name has been blocked by our filter, you cannot use miscellaneous characters. Alternative this field could been left blank.";
} Else {
$pass = htmlentities($_POST['password']);
$password = md5($pass);
$ip = $_SERVER['REMOTE_ADDR'];
$user = New user;
$signup = $user->signup($fname,$lname,$email,$password,$ip);
if ($signup == "Error on email") {
$error = "This email address is already in use, sorry";
} Else {
$_SESSION['id']= $signup;
}}}}
}
$design = "include/designs/".CURRENT_DESIGN."/";
include($design."design.top.inc.php");
// Start of content
if(isset($_SESSION['id'])) {
echo "<meta http-equiv='Refresh' content='0; url=https://website.com/'>
";
} else {
include($design."design.signup.inc.php");
}
// end of content
include($design."design.bottom.inc.php");
?>
PHP Code:<?php
session_start();
session_destroy();
include("include/config.inc.php");
include("include/classes/user.inc.php");
$design = "include/designs/".CURRENT_DESIGN."/";
include($design."design.top.inc.php");
include($design."design.login.inc.php");
// end of content
include($design."design.bottom.inc.php");
?>
PHP Code:<?php
session_start();
include("include/config.inc.php");
include("include/classes/user.inc.php");
if (isset($_POST['submit'])) {
$email = htmlentities($_POST['email']);
$pass = htmlentities($_POST['password']);
$password = md5($pass);
$user = New user;
$login = $user->login($email,$password);
if ($login == "Login error") {
echo "wrong information";
} Else {
$_SESSION['id']= $login;
}}
$design = "include/designs/".CURRENT_DESIGN."/";
include($design."design.top.inc.php");
// Start of content
if(isset($_SESSION['id'])) {
include($design."design.home.inc.php");
} else {
include($design."design.login.inc.php");
}
// end of content
include($design."design.bottom.inc.php");
?>
PHP Code:<?
$user = New user($_SESSION['id']);
$result = $user->userinfo;
echo $result->email."<br />";
echo $result->firstname."<br />";
echo $result->lastname."<br />";
echo $result->msn."<br />";
echo $result->aim."<br />";
echo $result->skype."<br />";
unset($user);
?>
PHP Code:<div id="login_holder">
<div class="login">
<span class="title"><span>Login</span></span>
<div class="content">
<form action="" method="post">
E-mail: <input type="email" name="email" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="submit" />
</form>
</div>
</div>
</div>
PHP Code:<div id="login_holder">
<div class="login">
<span class="title"><span>Signup</span></span>
<div class="content">
<? if ($error == "") {
} else {
echo $error;
}
?>
<form action="" method="post">
Firstname: <input type="text" name="fname" /><br />
Lastname: <input type="text" name="lname" /><br />
E-mail: <input type="email" name="email" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" name="submit" />
</form>
</div>
</div>
</div>
Lastly some tips this is what i use for my .htaccess
Code:#Start write engine RewriteEngine on #page 404 Page not found RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ 404.php #Hide index Options -Indexes
Regards,
Jordanxifyhosting Reviewed by xifyhosting on . PHP PDO login system, user class. Also Includes a theming system {Source} Hello, Before you look at the source I would like to say a huge thank you to Bennett's (http://btreptow.com/) who is one of my developer/beta tester for Graft Development. He has imputed allot of his own work into script, and i cannot take credit for the input he has put into this himself. Secondly I would like to thank Brad for help testing the script at each stage. config.inc.php <?php define("MYSQL_HOST","localhost"); define("MYSQL_USER","username"); Rating: 5
-
2nd Aug 2012, 10:13 AM #2MemberWebsite's:
Elite.SO Defendos.com Motionite.comLooks good mate
-
2nd Aug 2012, 10:20 AM #3Member
Looks sweet, nice post Jordan.
-
29th Aug 2012, 02:33 AM #4Member
very useful.
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
i want to add login system to my site...
By Havis in forum Webmaster DiscussionReplies: 5Last Post: 1st Aug 2012, 12:06 PM -
[Selling] jtLogin Secure Login System Nosql
By safeservicejt in forum Marketplace (Buy, Sell and Trade)Replies: 0Last Post: 14th Apr 2012, 10:49 AM -
Common Login System
By nairaweb in forum Web Development AreaReplies: 8Last Post: 10th Apr 2012, 02:23 PM -
[Hiring] Need A Coder For User Login System
By gopinath112 in forum Completed TransactionsReplies: 2Last Post: 25th Aug 2011, 05:27 PM -
User Referrer system
By Inevitable in forum vBulletinReplies: 1Last Post: 24th Apr 2009, 02:10 AM
themaCreator - create posts from...
Version 3.24 released. Open older version (or...