Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.44 KB | None | 0 0
  1. $DBhost = "localhost";
  2. $DBuser = "root";
  3. $DBpass = "";
  4. $DBname = "mysqli_login1";
  5.  
  6. $DBcon = new MySQLi($DBhost,$DBuser,$DBpass,$DBname);
  7.  
  8. if ($DBcon->connect_errno) {
  9. die("ERROR : -> ".$DBcon->connect_error);
  10. }
  11.  
  12. <?php
  13. session_start();
  14. include_once 'dbconnect.php';
  15.  
  16. if (!isset($_SESSION['userSession'])) {
  17. header("Location: index.php");
  18. }
  19.  
  20. $query = $DBcon->query("SELECT * FROM tbl_users WHERE user_id=".$_SESSION['userSession']);
  21. $userRow=$query->fetch_array();
  22. $DBcon->close();
  23.  
  24. ?>
  25. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  26. <html xmlns="http://www.w3.org/1999/xhtml">
  27. <head>
  28. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  29. <title>Welcome - <?php echo $userRow['email']; ?></title>
  30.  
  31. <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
  32. <link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
  33.  
  34. <link rel="stylesheet" href="style.css" type="text/css" />
  35. </head>
  36. <body>
  37.  
  38. <nav class="navbar navbar-default navbar-fixed-top">
  39. <div class="container">
  40. <div class="navbar-header">
  41. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
  42. <span class="sr-only">Toggle navigation</span>
  43. <span class="icon-bar"></span>
  44. <span class="icon-bar"></span>
  45. <span class="icon-bar"></span>
  46. </button>
  47. <a class="navbar-brand" href="">Coding Cage</a>
  48. </div>
  49. <div id="navbar" class="navbar-collapse collapse">
  50. <ul class="nav navbar-nav">
  51. <li class="active"><a href="link1">Back to Article</a></li>
  52. <li><a href="link2">jQuery</a></li>
  53. <li><a href="link3">PHP</a></li>
  54. </ul>
  55. <ul class="nav navbar-nav navbar-right">
  56. <li><a href="#"><span class="glyphicon glyphicon-user"></span>&nbsp; <?php echo $userRow['username']; ?></a></li>
  57. <li><a href="logout.php?logout"><span class="glyphicon glyphicon-log-out"></span>&nbsp; Logout</a></li>
  58. </ul>
  59. </div><!--/.nav-collapse -->
  60. </div>
  61. </nav>
  62.  
  63. <div class="container" style="margin-top:150px;text-align:center;font-family:Verdana, Geneva, sans-serif;font-size:35px;">
  64. <a href="link4/">Coding g</a><br /><br />
  65. <p>welcome</p>
  66. </div>
  67.  
  68. </body>
  69. </html>
  70.  
  71. <?php
  72. session_start();
  73. require_once 'dbconnect.php';
  74.  
  75. if (isset($_SESSION['userSession'])!="") {
  76. header("Location: home.php");
  77. exit;
  78. }
  79.  
  80. if (isset($_POST['btn-login'])) {
  81.  
  82. $email = strip_tags($_POST['email']);
  83. $password = strip_tags($_POST['password']);
  84.  
  85. $email = $DBcon->real_escape_string($email);
  86. $password = $DBcon->real_escape_string($password);
  87.  
  88. $query = $DBcon->query("SELECT user_id, email, password FROM tbl_users WHERE email='$email'");
  89. $row=$query->fetch_array();
  90.  
  91. $count = $query->num_rows; // if email/password are correct returns must be 1 row
  92.  
  93. if (password_verify($password, $row['password']) && $count==1) {
  94. $_SESSION['userSession'] = $row['user_id'];
  95. header("Location: home.php");
  96. } else {
  97. $msg = "<div class='alert alert-danger'>
  98. <span class='glyphicon glyphicon-info-sign'></span> &nbsp; Invalid Username or Password !
  99. </div>";
  100. }
  101. $DBcon->close();
  102. }
  103. ?>
  104. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  105. <html xmlns="http://www.w3.org/1999/xhtml">
  106. <head>
  107. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  108. <title>Coding Cage - Login & Registration System</title>
  109. <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
  110. <link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
  111. <link rel="stylesheet" href="style.css" type="text/css" />
  112. </head>
  113. <body>
  114.  
  115. <div class="signin-form">
  116.  
  117. <div class="container">
  118.  
  119.  
  120. <form class="form-signin" method="post" id="login-form">
  121.  
  122. <h2 class="form-signin-heading">Sign In.</h2><hr />
  123.  
  124. <?php
  125. if(isset($msg)){
  126. echo $msg;
  127. }
  128. ?>
  129.  
  130. <div class="form-group">
  131. <input type="email" class="form-control" placeholder="Email address" name="email" required />
  132. <span id="check-e"></span>
  133. </div>
  134.  
  135. <div class="form-group">
  136. <input type="password" class="form-control" placeholder="Password" name="password" required />
  137. </div>
  138.  
  139. <hr />
  140.  
  141. <div class="form-group">
  142. <button type="submit" class="btn btn-default" name="btn-login" id="btn-login">
  143. <span class="glyphicon glyphicon-log-in"></span> &nbsp; Sign In
  144. </button>
  145.  
  146. <a href="register.php" class="btn btn-default" style="float:right;">Sign UP Here</a>
  147.  
  148. </div>
  149.  
  150.  
  151.  
  152. </form>
  153.  
  154. </div>
  155.  
  156. </div>
  157.  
  158. </body>
  159. </html>
  160.  
  161. <?php
  162. session_start();
  163.  
  164. if (!isset($_SESSION['userSession'])) {
  165. header("Location: index.php");
  166. } else if (isset($_SESSION['userSession'])!="") {
  167. header("Location: home.php");
  168. }
  169.  
  170. if (isset($_GET['logout'])) {
  171. session_destroy();
  172. unset($_SESSION['userSession']);
  173. header("Location: index.php");
  174. }
  175.  
  176. -- phpMyAdmin SQL Dump
  177. -- version 4.1.14
  178. -- http://www.phpmyadmin.net
  179. --
  180. -- Host: 127.0.0.1
  181. -- Generation Time: Aug 14, 2016 at 08:16 PM
  182. -- Server version: 5.6.17
  183. -- PHP Version: 5.5.12
  184.  
  185. SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
  186. SET time_zone = "+00:00";
  187.  
  188.  
  189. /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  190. /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
  191. /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
  192. /*!40101 SET NAMES utf8 */;
  193.  
  194. --
  195. -- Database: `mysqli_login`
  196. --
  197.  
  198. -- --------------------------------------------------------
  199.  
  200. --
  201. -- Table structure for table `tbl_users`
  202. --
  203.  
  204. CREATE TABLE IF NOT EXISTS `tbl_users` (
  205. `user_id` int(11) NOT NULL AUTO_INCREMENT,
  206. `username` varchar(60) NOT NULL,
  207. `email` varchar(60) NOT NULL,
  208. `password` varchar(255) NOT NULL,
  209. PRIMARY KEY (`user_id`),
  210. UNIQUE KEY `email` (`email`)
  211. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
  212.  
  213. /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
  214. /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
  215. /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
  216.  
  217. <?php
  218. session_start();
  219. if (isset($_SESSION['userSession'])!="") {
  220. header("Location: home.php");
  221. }
  222. require_once 'dbconnect.php';
  223.  
  224. if(isset($_POST['btn-signup'])) {
  225.  
  226. $uname = strip_tags($_POST['username']);
  227. $email = strip_tags($_POST['email']);
  228. $upass = strip_tags($_POST['password']);
  229.  
  230. $uname = $DBcon->real_escape_string($uname);
  231. $email = $DBcon->real_escape_string($email);
  232. $upass = $DBcon->real_escape_string($upass);
  233.  
  234. $hashed_password = password_hash($upass, PASSWORD_DEFAULT); // this function works only in PHP 5.5 or latest version
  235.  
  236. $check_email = $DBcon->query("SELECT email FROM tbl_users WHERE email='$email'");
  237. $count=$check_email->num_rows;
  238.  
  239. if ($count==0) {
  240.  
  241. $query = "INSERT INTO tbl_users(username,email,password) VALUES('$uname','$email','$hashed_password')";
  242.  
  243. if ($DBcon->query($query)) {
  244. $msg = "<div class='alert alert-success'>
  245. <span class='glyphicon glyphicon-info-sign'></span> &nbsp; successfully registered !
  246. </div>";
  247. }else {
  248. $msg = "<div class='alert alert-danger'>
  249. <span class='glyphicon glyphicon-info-sign'></span> &nbsp; error while registering !
  250. </div>";
  251. }
  252.  
  253. } else {
  254.  
  255.  
  256. $msg = "<div class='alert alert-danger'>
  257. <span class='glyphicon glyphicon-info-sign'></span> &nbsp; sorry email already taken !
  258. </div>";
  259.  
  260. }
  261.  
  262. $DBcon->close();
  263. }
  264. ?>
  265. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  266. <html xmlns="http://www.w3.org/1999/xhtml">
  267. <head>
  268. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  269. <title>Login & Registration System</title>
  270. <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
  271. <link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
  272. <link rel="stylesheet" href="style.css" type="text/css" />
  273.  
  274. </head>
  275. <body>
  276.  
  277. <div class="signin-form">
  278.  
  279. <div class="container">
  280.  
  281.  
  282. <form class="form-signin" method="post" id="register-form">
  283.  
  284. <h2 class="form-signin-heading">Sign Up</h2><hr />
  285.  
  286. <?php
  287. if (isset($msg)) {
  288. echo $msg;
  289. }
  290. ?>
  291.  
  292. <div class="form-group">
  293. <input type="text" class="form-control" placeholder="Username" name="username" required />
  294. </div>
  295.  
  296. <div class="form-group">
  297. <input type="email" class="form-control" placeholder="Email address" name="email" required />
  298. <span id="check-e"></span>
  299. </div>
  300.  
  301. <div class="form-group">
  302. <input type="password" class="form-control" placeholder="Password" name="password" required />
  303. </div>
  304.  
  305. <hr />
  306.  
  307. <div class="form-group">
  308. <button type="submit" class="btn btn-default" name="btn-signup">
  309. <span class="glyphicon glyphicon-log-in"></span> &nbsp; Create Account
  310. </button>
  311. <a href="index.php" class="btn btn-default" style="float:right;">Log In Here</a>
  312. </div>
  313.  
  314. </form>
  315.  
  316. </div>
  317.  
  318. </div>
  319.  
  320. </body>
  321. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement