PHP-LOGIN PAGE - NESTED CODE || TECH FLOAT

Breaking

Post Top Ad

Post Top Ad

Friday, 7 September 2012

PHP-LOGIN PAGE


To make a basic Login Registration page by using language PHP, the codes are required, given below

Code to make the INDEX page ::

<?php require 'core.inc.php';
require 'connect.inc.php'; ?>
<?php

if(loggedin()) {
$firstname = getuserfield('firstname');
$surname = getuserfield('surname');
echo 'you\'re logged in, '.$firstname.' '.$surname.'.<a href="logout.php">log out</a>';

} else {

include 'loginform.inc.php';
}
?>

Paste this code and make the name of the file as “index.php”.


Now make a file as “conf.inc.php”

The code to make this file Is given below ::
<?php
$ip_address = $_SERVER['REMOTE_ADDR'];
$ip_blocked = array('127.0.0.1', '100.100.100.100');
?>
Pest this code and make the name of the file as “conf.inc.php”.

Now we will make the Data base connection. Here we will use MYSQL as back end.
The code for DATABASE connection
<?php
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = ' ';

$mysql_db = 'a_database';

if( !mysql_connect($mysql_host,$mysql_user,$mysql_pass) || !mysql_select_db($mysql_db))
{

                die(mysql_error());

}

?>

Paste this code and make the name of the file as “connect.inc.php”.


Now make an another file named as “core.inc.php”

And Paste the code
<?php
ob_start();
session_start();
$current_file = $_SERVER['SCRIPT_NAME'];

if(isset($_SERVER['HTTP_REFERER'])&&!empty($_SERVER['HTTP_REFERER'])) {
$http_referer = $_SERVER['HTTP_REFERER'];
}
function loggedin() {
                if(isset($_SESSION['user_id'])&& !empty($_SESSION['user_id'])) {
               
                                return true;
                } else {
                                                return false;
                }
}

function getuserfield($field) {
$query = "SELECT `$field` FROM `users` WHERE `id`='".$_SESSION['user_id']."'";
if ($query_run= mysql_query($query)) {
if($query_result = mysql_result($query_run, 0, $field)) {
return $query_result;
}
}
}

?>

You have already made the login page. Try these codes as the instructions are given.
In the next tutorial page we will make the log-out process and make the log in form.



No comments:

Post a Comment

Post Bottom Ad