Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.74 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>
  322.  
  323. <?php
  324.  
  325. require_once('dbconfig.php');
  326.  
  327. class USER
  328. {
  329.  
  330. private $conn;
  331.  
  332. public function __construct()
  333. {
  334. $database = new Database();
  335. $db = $database->dbConnection();
  336. $this->conn = $db;
  337. }
  338.  
  339. public function runQuery($sql)
  340. {
  341. $stmt = $this->conn->prepare($sql);
  342. return $stmt;
  343. }
  344.  
  345. public function register($uname,$umail,$upass)
  346. {
  347. try
  348. {
  349. $new_password = password_hash($upass, PASSWORD_DEFAULT);
  350.  
  351. $stmt = $this->conn->prepare("INSERT INTO users(user_name,user_email,user_pass)
  352. VALUES(:uname, :umail, :upass)");
  353.  
  354. $stmt->bindparam(":uname", $uname);
  355. $stmt->bindparam(":umail", $umail);
  356. $stmt->bindparam(":upass", $new_password);
  357.  
  358. $stmt->execute();
  359.  
  360. return $stmt;
  361. }
  362. catch(PDOException $e)
  363. {
  364. echo $e->getMessage();
  365. }
  366. }
  367.  
  368.  
  369. public function doLogin($uname,$umail,$upass)
  370. {
  371. try
  372. {
  373. $stmt = $this->conn->prepare("SELECT user_id, user_name, user_email, user_pass FROM users WHERE user_name=:uname OR user_email=:umail ");
  374. $stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
  375. $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
  376. if($stmt->rowCount() == 1)
  377. {
  378. if(password_verify($upass, $userRow['user_pass']))
  379. {
  380. $_SESSION['user_session'] = $userRow['user_id'];
  381. return true;
  382. }
  383. else
  384. {
  385. return false;
  386. }
  387. }
  388. }
  389. catch(PDOException $e)
  390. {
  391. echo $e->getMessage();
  392. }
  393. }
  394.  
  395. public function is_loggedin()
  396. {
  397. if(isset($_SESSION['user_session']))
  398. {
  399. return true;
  400. }
  401. }
  402.  
  403. public function redirect($url)
  404. {
  405. header("Location: $url");
  406. }
  407.  
  408. public function doLogout()
  409. {
  410. session_destroy();
  411. unset($_SESSION['user_session']);
  412. return true;
  413. }
  414. }
  415. ?>
  416.  
  417. <?php
  418. class Database
  419. {
  420. private $host = "localhost";
  421. private $db_name = "mysql_login2";
  422. private $username = "root";
  423. private $password = "";
  424. public $conn;
  425.  
  426. public function dbConnection()
  427. {
  428.  
  429. $this->conn = null;
  430. try
  431. {
  432. $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
  433. $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  434. }
  435. catch(PDOException $exception)
  436. {
  437. echo "Connection error: " . $exception->getMessage();
  438. }
  439.  
  440. return $this->conn;
  441. }
  442. }
  443. ?>
  444.  
  445. -- phpMyAdmin SQL Dump
  446. -- version 4.1.14
  447. -- http://www.phpmyadmin.net
  448. --
  449. -- Host: 127.0.0.1
  450. -- Generation Time: Jan 07, 2016 at 03:05 AM
  451. -- Server version: 5.6.17
  452. -- PHP Version: 5.5.12
  453.  
  454. SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
  455. SET time_zone = "+00:00";
  456.  
  457.  
  458. /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  459. /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
  460. /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
  461. /*!40101 SET NAMES utf8 */;
  462.  
  463. --
  464. -- Database: `dblogin`
  465. --
  466.  
  467. -- --------------------------------------------------------
  468.  
  469. --
  470. -- Table structure for table `users`
  471. --
  472.  
  473. CREATE TABLE IF NOT EXISTS `users` (
  474. `user_id` int(11) NOT NULL AUTO_INCREMENT,
  475. `user_name` varchar(15) NOT NULL,
  476. `user_email` varchar(40) NOT NULL,
  477. `user_pass` varchar(255) NOT NULL,
  478. `joining_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  479. PRIMARY KEY (`user_id`)
  480. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
  481.  
  482. /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
  483. /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
  484. /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
  485.  
  486. <?php
  487.  
  488. require_once("session.php");
  489.  
  490. require_once("class.user.php");
  491. $auth_user = new USER();
  492.  
  493.  
  494. $user_id = $_SESSION['user_session'];
  495.  
  496. $stmt = $auth_user->runQuery("SELECT * FROM users WHERE user_id=:user_id");
  497. $stmt->execute(array(":user_id"=>$user_id));
  498.  
  499. $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
  500.  
  501. ?>
  502. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  503. <html xmlns="http://www.w3.org/1999/xhtml">
  504. <head>
  505. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  506. <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
  507. <link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
  508. <script type="text/javascript" src="jquery-1.11.3-jquery.min.js"></script>
  509. <link rel="stylesheet" href="style.css" type="text/css" />
  510. <title>welcome - <?php print($userRow['user_email']); ?></title>
  511. </head>
  512.  
  513. <body>
  514.  
  515. <nav class="navbar navbar-default navbar-fixed-top">
  516. <div class="container">
  517. <div class="navbar-header">
  518. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
  519. <span class="sr-only">Toggle navigation</span>
  520. <span class="icon-bar"></span>
  521. <span class="icon-bar"></span>
  522. <span class="icon-bar"></span>
  523. </button>
  524. <a class="navbar-brand" href="http://www.website.com">site</a>
  525. </div>
  526. <div id="navbar" class="navbar-collapse collapse">
  527. <ul class="nav navbar-nav">
  528. <li class="active"><a href="http://www.website.com/login">Back to Article</a></li>
  529. <li><a href="link9">jQuery</a></li>
  530. <li><a href="link789">PHP</a></li>
  531. </ul>
  532. <ul class="nav navbar-nav navbar-right">
  533.  
  534. <li class="dropdown">
  535. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
  536. <span class="glyphicon glyphicon-user"></span>&nbsp;Hi' <?php echo $userRow['user_email']; ?>&nbsp;<span class="caret"></span></a>
  537. <ul class="dropdown-menu">
  538. <li><a href="profile.php"><span class="glyphicon glyphicon-user"></span>&nbsp;View Profile</a></li>
  539. <li><a href="logout.php?logout=true"><span class="glyphicon glyphicon-log-out"></span>&nbsp;Sign Out</a></li>
  540. </ul>
  541. </li>
  542. </ul>
  543. </div><!--/.nav-collapse -->
  544. </div>
  545. </nav>
  546.  
  547.  
  548. <div class="clearfix"></div>
  549.  
  550.  
  551. <div class="container-fluid" style="margin-top:80px;">
  552.  
  553. <div class="container">
  554.  
  555. <label class="h5">welcome : <?php print($userRow['user_name']); ?></label>
  556. <hr />
  557.  
  558. <h1>
  559. <a href="home.php"><span class="glyphicon glyphicon-home"></span> home</a> &nbsp;
  560. <a href="profile.php"><span class="glyphicon glyphicon-user"></span> profile</a></h1>
  561. <hr />
  562.  
  563. <p class="h4">User Home Page</p>
  564.  
  565.  
  566. <p class="blockquote-reverse" style="margin-top:200px;">
  567. website themes<br /><br />
  568. <a href="link4">login here</a>
  569. </p>
  570.  
  571. </div>
  572.  
  573. </div>
  574.  
  575. <script src="bootstrap/js/bootstrap.min.js"></script>
  576.  
  577. </body>
  578. </html>
  579.  
  580. <?php
  581. session_start();
  582. require_once("class.user.php");
  583. $login = new USER();
  584.  
  585. if($login->is_loggedin()!="")
  586. {
  587. $login->redirect('home.php');
  588. }
  589.  
  590. if(isset($_POST['btn-login']))
  591. {
  592. $uname = strip_tags($_POST['txt_uname_email']);
  593. $umail = strip_tags($_POST['txt_uname_email']);
  594. $upass = strip_tags($_POST['txt_password']);
  595.  
  596. if($login->doLogin($uname,$umail,$upass))
  597. {
  598. $login->redirect('home.php');
  599. }
  600. else
  601. {
  602. $error = "Wrong Details !";
  603. }
  604. }
  605. ?>
  606. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  607. <html xmlns="http://www.w3.org/1999/xhtml">
  608. <head>
  609. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  610. <title>Coding Cage : Login</title>
  611. <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
  612. <link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
  613. <link rel="stylesheet" href="style.css" type="text/css" />
  614. </head>
  615. <body>
  616.  
  617. <div class="signin-form">
  618.  
  619. <div class="container">
  620.  
  621.  
  622. <form class="form-signin" method="post" id="login-form">
  623.  
  624. <h2 class="form-signin-heading">Log In to WebApp.</h2><hr />
  625.  
  626. <div id="error">
  627. <?php
  628. if(isset($error))
  629. {
  630. ?>
  631. <div class="alert alert-danger">
  632. <i class="glyphicon glyphicon-warning-sign"></i> &nbsp; <?php echo $error; ?> !
  633. </div>
  634. <?php
  635. }
  636. ?>
  637. </div>
  638.  
  639. <div class="form-group">
  640. <input type="text" class="form-control" name="txt_uname_email" placeholder="Username or E mail ID" required />
  641. <span id="check-e"></span>
  642. </div>
  643.  
  644. <div class="form-group">
  645. <input type="password" class="form-control" name="txt_password" placeholder="Your Password" />
  646. </div>
  647.  
  648. <hr />
  649.  
  650. <div class="form-group">
  651. <button type="submit" name="btn-login" class="btn btn-default">
  652. <i class="glyphicon glyphicon-log-in"></i> &nbsp; SIGN IN
  653. </button>
  654. </div>
  655. <br />
  656. <label>Don't have account yet ! <a href="sign-up.php">Sign Up</a></label>
  657. </form>
  658.  
  659. </div>
  660.  
  661. </div>
  662.  
  663. </body>
  664. </html>
  665.  
  666. <?php
  667. require_once('session.php');
  668. require_once('class.user.php');
  669. $user_logout = new USER();
  670.  
  671. if($user_logout->is_loggedin()!="")
  672. {
  673. $user_logout->redirect('home.php');
  674. }
  675. if(isset($_GET['logout']) && $_GET['logout']=="true")
  676. {
  677. $user_logout->doLogout();
  678. $user_logout->redirect('index.php');
  679. }
  680.  
  681. <?php
  682.  
  683. require_once("session.php");
  684.  
  685. require_once("class.user.php");
  686. $auth_user = new USER();
  687.  
  688.  
  689. $user_id = $_SESSION['user_session'];
  690.  
  691. $stmt = $auth_user->runQuery("SELECT * FROM users WHERE user_id=:user_id");
  692. $stmt->execute(array(":user_id"=>$user_id));
  693.  
  694. $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
  695.  
  696. ?>
  697. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  698. <html xmlns="http://www.w3.org/1999/xhtml">
  699. <head>
  700. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  701. <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
  702. <link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
  703. <script type="text/javascript" src="jquery-1.11.3-jquery.min.js"></script>
  704. <link rel="stylesheet" href="style.css" type="text/css" />
  705. <title>welcome - <?php print($userRow['user_email']); ?></title>
  706. </head>
  707.  
  708. <body>
  709.  
  710.  
  711. <nav class="navbar navbar-default navbar-fixed-top">
  712. <div class="container">
  713. <div class="navbar-header">
  714. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
  715. <span class="sr-only">Toggle navigation</span>
  716. <span class="icon-bar"></span>
  717. <span class="icon-bar"></span>
  718. <span class="icon-bar"></span>
  719. </button>
  720. <a class="navbar-brand" href="http://oursite.com">Coding Cage</a>
  721. </div>
  722. <div id="navbar" class="navbar-collapse collapse">
  723. <ul class="nav navbar-nav">
  724. <li class="active"><a href="link8">Back to site</a></li>
  725. <li><a href="link9">j</a></li>
  726. <li><a href="link10">P</a></li>
  727. </ul>
  728. <ul class="nav navbar-nav navbar-right">
  729.  
  730. <li class="dropdown">
  731. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
  732. <span class="glyphicon glyphicon-user"></span>&nbsp;Hi' <?php echo $userRow['user_email']; ?>&nbsp;<span class="caret"></span></a>
  733. <ul class="dropdown-menu">
  734. <li><a href="#"><span class="glyphicon glyphicon-user"></span>&nbsp;View Profile</a></li>
  735. <li><a href="logout.php?logout=true"><span class="glyphicon glyphicon-log-out"></span>&nbsp;Sign Out</a></li>
  736. </ul>
  737. </li>
  738. </ul>
  739. </div><!--/.nav-collapse -->
  740. </div>
  741. </nav>
  742.  
  743. <div class="clearfix"></div>
  744.  
  745. <div class="container-fluid" style="margin-top:80px;">
  746.  
  747. <div class="container">
  748.  
  749. <label class="h5">welcome : <?php print($userRow['user_name']); ?></label>
  750. <hr />
  751.  
  752. <h1>
  753. <a href="home.php"><span class="glyphicon glyphicon-home"></span> home</a> &nbsp;
  754. <a href="profile.php"><span class="glyphicon glyphicon-user"></span> profile</a></h1>
  755. <hr />
  756.  
  757. <p class="h4">Another Secure Profile Page</p>
  758.  
  759. <p class="blockquote-reverse" style="margin-top:200px;">
  760. nice<br /><br />
  761. <a href="link5">site link</a>
  762. </p>
  763.  
  764. </div>
  765.  
  766. </div>
  767.  
  768.  
  769.  
  770.  
  771. <script src="bootstrap/js/bootstrap.min.js"></script>
  772.  
  773. </body>
  774. </html>
  775.  
  776. <?php
  777.  
  778. session_start();
  779.  
  780. require_once 'class.user.php';
  781. $session = new USER();
  782.  
  783. // if user session is not active(not loggedin) this page will help 'home.php and profile.php' to redirect to login page
  784. // put this file within secured pages that users (users can't access without login)
  785.  
  786. if(!$session->is_loggedin())
  787. {
  788. // session no set redirects to login page
  789. $session->redirect('index.php');
  790. }
  791.  
  792. <?php
  793. session_start();
  794. require_once('class.user.php');
  795. $user = new USER();
  796.  
  797. if($user->is_loggedin()!="")
  798. {
  799. $user->redirect('home.php');
  800. }
  801.  
  802. if(isset($_POST['btn-signup']))
  803. {
  804. $uname = strip_tags($_POST['txt_uname']);
  805. $umail = strip_tags($_POST['txt_umail']);
  806. $upass = strip_tags($_POST['txt_upass']);
  807.  
  808. if($uname=="") {
  809. $error[] = "provide username !";
  810. }
  811. else if($umail=="") {
  812. $error[] = "provide email id !";
  813. }
  814. else if(!filter_var($umail, FILTER_VALIDATE_EMAIL)) {
  815. $error[] = 'Please enter a valid email address !';
  816. }
  817. else if($upass=="") {
  818. $error[] = "provide password !";
  819. }
  820. else if(strlen($upass) < 6){
  821. $error[] = "Password must be atleast 6 characters";
  822. }
  823. else
  824. {
  825. try
  826. {
  827. $stmt = $user->runQuery("SELECT user_name, user_email FROM users WHERE user_name=:uname OR user_email=:umail");
  828. $stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
  829. $row=$stmt->fetch(PDO::FETCH_ASSOC);
  830.  
  831. if($row['user_name']==$uname) {
  832. $error[] = "sorry username already taken !";
  833. }
  834. else if($row['user_email']==$umail) {
  835. $error[] = "sorry email id already taken !";
  836. }
  837. else
  838. {
  839. if($user->register($uname,$umail,$upass)){
  840. $user->redirect('sign-up.php?joined');
  841. }
  842. }
  843. }
  844. catch(PDOException $e)
  845. {
  846. echo $e->getMessage();
  847. }
  848. }
  849. }
  850.  
  851. ?>
  852. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  853. <html xmlns="http://www.w3.org/1999/xhtml">
  854. <head>
  855. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  856. <title>Coding Cage : Sign up</title>
  857. <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
  858. <link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
  859. <link rel="stylesheet" href="style.css" type="text/css" />
  860. </head>
  861. <body>
  862.  
  863. <div class="signin-form">
  864.  
  865. <div class="container">
  866.  
  867. <form method="post" class="form-signin">
  868. <h2 class="form-signin-heading">Sign up.</h2><hr />
  869. <?php
  870. if(isset($error))
  871. {
  872. foreach($error as $error)
  873. {
  874. ?>
  875. <div class="alert alert-danger">
  876. <i class="glyphicon glyphicon-warning-sign"></i> &nbsp; <?php echo $error; ?>
  877. </div>
  878. <?php
  879. }
  880. }
  881. else if(isset($_GET['joined']))
  882. {
  883. ?>
  884. <div class="alert alert-info">
  885. <i class="glyphicon glyphicon-log-in"></i> &nbsp; Successfully registered <a href='index.php'>login</a> here
  886. </div>
  887. <?php
  888. }
  889. ?>
  890. <div class="form-group">
  891. <input type="text" class="form-control" name="txt_uname" placeholder="Enter Username" value="<?php if(isset($error)){echo $uname;}?>" />
  892. </div>
  893. <div class="form-group">
  894. <input type="text" class="form-control" name="txt_umail" placeholder="Enter E-Mail ID" value="<?php if(isset($error)){echo $umail;}?>" />
  895. </div>
  896. <div class="form-group">
  897. <input type="password" class="form-control" name="txt_upass" placeholder="Enter Password" />
  898. </div>
  899. <div class="clearfix"></div><hr />
  900. <div class="form-group">
  901. <button type="submit" class="btn btn-primary" name="btn-signup">
  902. <i class="glyphicon glyphicon-open-file"></i>&nbsp;SIGN UP
  903. </button>
  904. </div>
  905. <br />
  906. <label>have an account ! <a href="index.php">Sign In</a></label>
  907. </form>
  908. </div>
  909. </div>
  910.  
  911. </div>
  912.  
  913. </body>
  914. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement