php mysql tutorial n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
PHP MySQL TUTORIAL PowerPoint Presentation
Download Presentation
PHP MySQL TUTORIAL

Loading in 2 Seconds...

play fullscreen
1 / 15

PHP MySQL TUTORIAL - PowerPoint PPT Presentation


  • 115 Views
  • Uploaded on

PHP MySQL TUTORIAL. SIMPLE LOGIN SYSTEM. Introduction. Login is a very important part of any website, from securing contents from prying eyes to tracking visitors on your website. This tutorial is a simple login form for a website.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'PHP MySQL TUTORIAL' - anais


Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
php mysql tutorial

PHP MySQL TUTORIAL

SIMPLE LOGIN SYSTEM

introduction
Introduction
  • Login is a very important part of any website, from securing contents from prying eyes to tracking visitors on your website.
  • This tutorial is a simple login form for a website.
  • Firstly, make a new file called "login.php" and start off by writing this code:
the code
The code
  • <?php
  • session_start(); 
  • mysql_connect(“localhost","PUT YOUR DATABASE USER HERE","PUT YOUR DATABASE PASSWORD HERE"); 
  • mysql_select_db("PUT YOUR DATABASE HERE");
the code1
The code
  • if(isset($_SESSION['loggedin'])){die("You are already logged in!");}
  • if(isset($_POST['submit'])){   $name = mysql_real_escape_string($_POST['username']); 
  • $pass = mysql_real_escape_string($_POST['password']); 
the code2
The code
  • $mysql = mysql_query("SELECT * FROM users WHERE name = '$name' AND password = '$pass'");
  •    if(mysql_num_rows($mysql) < 1)   {     die("Password was probably incorrect!");

}

the code3
The code
  • $_SESSION['loggedin'] = "YES"; 
  • $_SESSION['name'] = $name; 
  • echo '<script type="text/javascript"> window.location = "index.php"</script>';
  • die("You are now logged in!");
  • }
the code4
The code

echo "<form type='login.php' method='POST'>Username: <br><input type='text' name='username'><br>Password: <br><input type='password' name='password'>

<br><input type='submit' name='submit' value='Login'></form>";

?>

database
Database
  • After you have put that code, run this query on your database:

CREATE TABLE `users` (`id` BIGINT( 60 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,`name` VARCHAR( 50 ) NOT NULL ,`password` VARCHAR( 32 ) NOT NULL ,`date` INT( 32 ) NOT NULL ,`email` VARCHAR( 80 ) NOT NULL);

slide9
Next
  • And then add all of the users you wish to the table!
  • To integrate this within your website, you can do the following at the top of your site:
slide10

<?phpsession_start(); // NEVER forget this!if(!isset($_SESSION['loggedin'])){die("To access this page, you need to <a href='login.php'>LOGIN</a>"); <?phpsession_start(); // NEVER forget this!if(!isset($_SESSION['loggedin'])){die("To access this page, you need to <a href='login.php'>LOGIN</a>"); 

}

?>

l ist records php
list_records.php

<?php

session_start(); // NEVER forget this!if(!isset($_SESSION['loggedin'])){die("To access this page, you need to <a href='login.php'>LOGIN</a>"); 

}

slide12

And to say like "Hello there, {USERNAME}" you would put this snippet anywhere you want it to appear:

<?php echo " Hello there, ".$_SESSION['name'] ;?>

  • Remember, DO NOT FORGET "session_start();" at the top of every page in which you want the user to log in or be logged in to access!
redirect
Redirect
  • echo '<script type="text/javascript"> window.location = “secure_page.php"</script>';
  • header('location:destinations.php?‘);
logout php
logout.php

<?php

session_start();

if($_GET['do'] == "logout") {

unset($_SESSION['loggedin']);

unset($_SESSION['name']);

session_destroy();

echo '<script type="text/javascript"> window.location = "login.php"</script>';

}

slide15

<a href="logout.php?do=logout" title="Logout" onclick="return confirm('Are you sure you want to logout?')">Logout</a>