Showing posts with label login php script. Show all posts
Showing posts with label login php script. Show all posts

Saturday 24 October 2015

session example in php very easy to understand beginner must read



<?php
session_start();

if(!isset($_SESSION['userID']) || (trim($_SESSION['userID']) == '')){
    header('location:index.php');
    exit();
}

$session_id = $_SESSION['userID'];
$session_id = $_SESSION['username'];


?>
$_SESSION :-   userID and username is a DATABASE NAME  as shown in dig


Session variables are used to store individual client’s information on web server for later use,  as web server does not know which client’s request to be respond because, HTTP address does not maintained state.


>>Cookies and Session diff
  1. Cookies are returned and stored in the user's browser, session data is stored on your web server.
  2. The life span of a cookie can be set to almost any duration of your choosing. PHP sessions have a predetermined short life. The exact life span depends on how your web host has configured PHP on your server.
  3. Depending on how your web server is configured, session data is often stored in a public temporary directory on the server. As such it is possible that other users on the server may be able to peek at the data you store there.

A session creates a file in a temporary directory on the server where registered session variables and their values are stored. This data will be available to all pages on the site during that visit.
The location of the temporary file is determined by a setting in the php.ini file called session.save_path. Bore using any session variable make sure you have setup this path.
When a session is started following things happen −
  • PHP first creates a unique identifier for that particular session which is a random string of 32 hexadecimal numbers such as 3c7foj34c3jj973hjkop2fc937e3443.
  • A cookie called PHPSESSID is automatically sent to the user's computer to store unique session identification string.
  • A file is automatically created on the server in the designated temporary directory and bears the name of the unique identifier prefixed by sess_ ie sess_3c7foj34c3jj973hjkop2fc937e3443.

-----------------------------------------------------------
$_GET EXAMPlE

 <table align="center" border="1" cellspacing="0" width="500">
                    <tr>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Action</th>
                    </tr>
                    <?php
                    $sql = "SELECT * FROM info_tbl";
                    $result = $conn->query($sql);
                    if($result->num_rows > 0){
                    while($row = $result->fetch_array()){
                        ?>
                        <tr>
                            <td align="center"><?php echo $row['firstName'];?></td>
                            <td align="center"><?php echo $row['lastName'];?></td>
                            <td align="center"><a href="edit.php?infoID=<?php echo md5($row['infoID']);?>">Edit
                            </a>/<a href="delete.php?infoID=<?php echo md5($row['infoID']);?>">Delete</a></td>
                        </tr>
                        <?php
                            }  
                        }else{
                            echo "<center><p> No Records</p></center>";
                        }

---------------------------------------------------

<?php
include 'conn.php';
include 'session.php';

$id = $_GET['infoID'];
$view = "SELECT * from info_tbl where md5(infoID) = '$id'";
$result = $conn->query($view);
$row = $result->fetch_assoc();

if(isset($_POST['update'])){

    $ID = $_GET['infoID'];

    $fn = $_POST['fname'];
    $ln = $_POST['lname'];

    $insert = "UPDATE info_tbl set firstName = '$fn', lastName = '$ln' where md5(infoID) = '$ID'";
   
    if($conn->query($insert)== TRUE){

            echo "Sucessfully update data";
            header('location:maintenance.php');           
    }else{

        echo "Ooppss cannot add data" . $conn->error;
        header('location:maintenance.php');
    }
    $conn->close();
}
?>

 ........................................................................................................
FOREACH ARRAY

Friday 3 October 2014

LOGIN SCRIPT IN PHP MYSQL FULL PROJECT DOWNLOAD

AAVIK KUMAR PRODUCTION



main.php
---------------------------
<?php
/*
 * Main.php
 *
 * This is an example of the main page of a website. Here users will be able to login.
 * However, like on most sites the login form doesn't just have to be on the main page,
 * but re-appear on subsequent pages, depending on whether the user has logged in or not.
 *
 * Originally written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
 * Last Updated by the Angry Frog: October 19, 2011
*/

include("include/session.php");
global $database;
$config = $database->getConfigs();
?>

<html>
<head>
<title><?php echo $config['SITE_NAME']; ?> - Main</title>

<style type="text/css">

html body {
margin: 100;
padding: 0;
background-color: #C8DFF6;
}
body {
    font: 12px/1.5 Lucida Grande, Arial, Helvetica, 'Liberation Sans', FreeSans, sans-serif;
     background-image:url('ppl.jpg');
     background-position: right center;;
     background-repeat: no-repeat;
    
}


</style>
</head>
<body>

<table>
<tr><td>


<?php
/**
 * User has already logged in, so display relavent links, including
 * a link to the admin center if the user is an administrator.
 */
if($session->logged_in){
   echo "<h1>Logged In</h1>";
   echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
       ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"
       ."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;";
   if($session->isAdmin()){
      echo "[<a href=\"admin/index.php\">Admin Center</a>] &nbsp;&nbsp;";
   }
   echo "[<a href=\"process.php\">Logout</a>]";
}
else{
?>

<h1>Connecting World!!!</h1>
<br/>
<?php
/**
 * User not logged in, display the login form.
 * If user has already tried to login, but errors were
 * found, display the total number of errors.
 * If errors occurred, they will be displayed.
 */
if($form->num_errors > 0){
   echo $form->num_errors." error(s) found";
}
?>
<fieldset>
  <legend>LOGIN:</legend>
<form action="process.php" method="POST">

<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<?php echo $form->value("user"); ?>"></td><td><?php echo $form->error("user"); ?></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<?php echo $form->value("pass"); ?>"></td><td><?php echo $form->error("pass"); ?></td></tr>
<tr><td colspan="2" align="left"><input type="checkbox" name="remember" <?php if($form->value("remember") != ""){ echo "checked"; } ?>>
Remember me &nbsp;&nbsp;&nbsp;&nbsp;
<input type="hidden" name="sublogin" value="1">
<input type="submit" value="Login"></td></tr>
<tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr>
<tr><td colspan="2" align="left"><br>Not registered? <a href="register.php">Sign-Up!</a></td></tr>
</table>
</form>
</fieldset>

</td></tr>
</table>
<?php
}
echo "<br><br>";
include("include/view_active.php");
?>

</body>
</html>

constant.php
--------------------------
<?php
/**
 * Database Constants - these constants are required
 * in order for there to be a successful connection
 * to the MySQL database. Make sure the information is
 * correct.
 */

define("DB_SERVER", "localhost");
define("DB_USER", "root");
define("DB_PASS", "");
define("DB_NAME", "bestloginphp");

/**
 * Database Table Constants - these constants
 * hold the names of all the database tables used
 * in the script.
 */
define("TBL_USERS", "users");


DOWNLOAD FULL CODE BY AAVIK KUMAR