Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to get session variables from cookie string

<?php
require_once 'login.php';

$connection = new mysqli($db_hostname,$db_username,$db_password,$db_database);
if($connection->connect_error) die ($connect->connect_error);

if (isset($_SERVER['PHP_AUTH_USER']) &&
   isset($_SERVER['PHP_AUTH_PW']))
    {
        $username = mysql_entities_fix($connection,$_SERVER['PHP_AUTH_USER']);
        $password = mysql_entities_fix($connection,$_SERVER['PHP_AUTH_PW']);

        $query = "SELECT * FROM user WHERE username = '$username'";

        $result = $connection->query($query);

        if(!$result) die ($connection->error);
        elseif ($result->num_rows) 
        {
            $row = $result->fetch_array(MYSQLI_NUM);    
            $result->close();
            $salt1="!@#$";
            $salt2="$#@!";
            $token = hash('ripemd128',"$salt1$password$salt2"); 

            if($token == $row[3])
                {
                    session_start();
                    $_SESSION['username'] = $username;
                    $_SESSION['password'] = $password;
                    $_SESSION['forename'] = $row[0];
                    $_SESSION['surname'] = $row[1];
                        echo "$row[0] $row[1] : Hi '$row[0]' you are logged
                            in as '$row[2]'";
                    die("<p><a href = continue.php> CLICK HERE TO CONTINUE</a></p>");
                }
            else    {die("Invalid Username/ Password Combination");}            
        }
        else
            {
                die("Invalid Username/ Password Combination");
            }
    }
else
    {
            header('WWW-Authenticate: Basic realm="Restricted Section"');
                header('HTTP/1.0 401 Unauthorized');
                die("Please enter your username and password to Login");
    }
    $connection->close();
function mysql_entities_fix($connection,$var)
    {
        return htmlentities(mysql_entities_string($connection,$var));
    }
function mysql_entities_string($connection,$var)
    {
        if (get_magic_quotes_gpc()) $var = stripslahes($var);
        return $connection->real_escape_string($var);

    }
?>
Comment

PREVIOUS NEXT
Code Example
Php :: email in ctf 
Php :: install php 7.4 amazon linux 2 
Php :: how to sum values of two product which are same gst rate and this product are come from foreach loop in php 
Php :: Primary Termmaatwebsite/excel store s3 
Php :: mysql php update sum same table 
Php :: Comment exiger une longueur minimale de commentaire dans WordPress 
Php :: laravel 7 link to another page with language prefix 
Php :: wordpress add_action echo on edit page 
Php :: update query not working no errors found php mysql 
Php :: Change Initial Country For Caldera Forms Phone Fields 
Php :: Declaration of AppExportsTarefasExport::headings() must be compatible with MaatwebsiteExcelConcernsWithHeadings::headings(): array 
Php :: php array key value print 
Php :: wordpress remove current post in sidebar php 
Php :: Akkhor - School Management Admin Template download 
Php :: get_user_info 
Php :: extension gd missing laravel composer update 
Php :: laravel join with count 
Php :: small echo php 
Php :: Laravel advanced sub queries 
Php :: php docblock 
Php :: php Least prime factor of numbers till n 
Php :: publish algolia search in laravel 
Php :: login with google account using php source code download 
Php :: if ( $post_armi-have_posts() ) { while ($post_armi-have_posts() ) { $post_armi-the_post(); 
Php :: Inject interface and not concrete class 
Php :: php wxplode 
Php :: désinfecte email php 
Php :: PHP OOP - Interfaces 
Php :: filter data in wordpress 
Php :: woocommerce affiliate product link image to external link 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =