PHP Classes

PHP User Identification: Get and set user identification details

Recommend this page to a friend!
  Info   Example   Demos   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 498 All time: 5,832 This week: 660Up
Version License PHP version Categories
user-identification 1.0GNU General Publi...5.3PHP 5, User Management
Description 

Author

This class can get and set user identification details.

It can retrieve details about the user such its geographic location based the IP address obtained from ipinfo.io, city, country, preferred language, host name, etc..

The details are stored in session variables. Applications can also set other custom variables such as the authenticated user name, personal name, etc..

Picture of Ricky Scotti
  Performance   Level  
Name: Ricky Scotti <contact>
Classes: 3 packages by
Country: Switzerland Switzerland

Recommendations

I need a PHP class for professional login system
Create a professional login system

Example

<?php
/**
 * Created by Riccardo Scotti.
 * User: Riccardo Scotti
 * Date: 18/08/15
 */


/*
 * IMPORTANT!! ob_start(); is essential for unset cookies. If you don't use this two method you can comment this line.
 * Methods: unSetUser() destroyUser()
 */

ob_start();

    require_once(
'./lib/class/class.users.php');

   
//class to call
   
$user= new USERS\Identify();

   
/* AUTO LANGUAGE DETECTED BY BROWSER */
   
echo 'Language: '.$user->getUser('_language').'<br>'.PHP_EOL;

   
/* IF IpLocation = true; SET VALUE CONSTANT IN CLASS*/
   
echo 'City: '.$user->getUser('_city').'<br>'.PHP_EOL;
    echo
'IP: '.$user->getUser('_ip').'<br>'.PHP_EOL;
    echo
'Hostname: '.$user->getUser('_hostname').'<br>'.PHP_EOL;
    echo
'Country: '.$user->getUser('_country').'<br>'.PHP_EOL;
    echo
'Localization: '.$user->getUser('_localization').'<br>'.PHP_EOL;
   
/**/

   
echo '<hr>'.PHP_EOL;
    echo
'Corrected call to the Class:';
    echo
'<br>'.PHP_EOL;

    echo
'Set var UserName already setted in class array :';
   
$user->setUser('UserName','Ricky Scotti');
    echo
$user->getUser('UserName').'<br>'.PHP_EOL;

    echo
'Create var "author" will not be recorded in cookies, set and display:';
   
$user->createParameter('author',0); //parameter 0-1 for record in cookies
   
$user->setUser('author','Ricky Scotti');
    echo
$user->getUser('author').'<br>'.PHP_EOL;

    echo
'Create var "webmaster" will be recorded in cookies, set and display:';
   
$user->createParameter('webmaster',1); //parameter 0-1 for record in cookies
   
$user->setUser('webmaster','Ricky Scotti');
    echo
$user->getUser('webmaster').'<br>'.PHP_EOL;

    echo
'Change language:';
   
$user->setLanguage('fr');
    echo
$user->getUser('_language').'<br>'.PHP_EOL;

    echo
'<hr>'.PHP_EOL;
    echo
'Wronged call to class:';
    echo
'<br>'.PHP_EOL;

   
/* SOME ERROR */
   
if($user->createParameter('UserName',0)===false){
        echo
'Var already exist or private! Not Set<br>'.PHP_EOL;
    };

    if(
$user->setUser('_language',"fr")===false){
        echo
'Var not found or private!<br>'.PHP_EOL;
    };

    if(
$user->getUser('test')===false){
        echo
'Var not found!<br>'.PHP_EOL;
    };
   
/*END ERROR */

    /* SET VERIFY USER */
    /* For example after a verified login, uncomment line under*/
    //$user->loginVerifiedUser();

   
if ($user->userIdentified()==1){
       
/*USER VERIFIED IN THIS SESSION*/
       
echo 'User Verified<br>'.PHP_EOL;
    } else {
       
/*USER not VERIFIED IN THIS SESSION*/
       
echo 'User Not Verified<br>'.PHP_EOL;
    }

   
/* UNSET VERIFY USER */
    /* For example after a logoff, uncomment line under */
    //$user->unSetUser();



    /* ALERT: DELETE COOKIES AND UNSET SESSION */
    //$user->destroyUser();


  ExampleExternal page  
  Files folder image Files (2)  
File Role Description
Files folder imagelib (1 directory)
Plain text file session.php Example Example file

  Files folder image Files (2)  /  lib  
File Role Description
Files folder imageclass (1 file)

  Files folder image Files (2)  /  lib  /  class  
File Role Description
  Plain text file class.users.php Class Class file

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:498
This week:0
All time:5,832
This week:660Up