WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Shows how to parse a file and how to use the new __get magic method (PHP5). The provided class can be used in any unix-like environment to retrieve user information (you must have access to /etc/passwd in order to work).
Categories : PHP, PHP Classes, Filesystem Click here to Update Your Picture
Victor Roman Archidona
Date : Jul 09th 2007
Grade : 5 of 5 (graded 1 times)
Viewed : 1320
File : 4673.zip
Images : No Images for this code example.
Search : More code by Victor Roman Archidona
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 



Usage Example
<?php
require_once "userinfo.class.php";

$user = new UserInfo("apache");

echo
"Username: ".$user->username."\n";
echo
"User ID: ".$user->uid."\n";
echo
"Group ID: ".$user->gid."\n";
echo
"Comment: ".$user->comment."\n";
echo
"Home: ".$user->home."\n";
echo
"Shell: ".$user->shell."\n";
?>



userinfo.class.php
<?php
/*
* Simple script to retrieve the user information from an
* /etc/passwd file for unix-like OSes
*
* Copyright (C) 2007 Victor Roman Archidona
* http://blog.daijo.org
*/

class UserInfo
{
    private
$_user_info = null;

    public function
__construct($user)
    {
       
$entry = $this->getUserEntry($user);
       
$this->processUserEntry($entry);
    }

    public function
getUserInfo()
    {
        return
$this->_user_info;
    }


    public function
__get($var)
    {
        if (
array_key_exists($var, $this->_user_info))
            return
$this->_user_info[$var];

        return
null;
    }

    private function
processUserEntry($entry)
    {
        list(
$this->_user_info["username"],
             
$this->_user_info["unused"],
             
$this->_user_info["uid"],
             
$this->_user_info["gid"],
             
$this->_user_info["comment"],
             
$this->_user_info["home"],
             
$this->_user_info["shell"]) = explode(":", $entry);

       
$this->_user_info["shell"] = trim($this->_user_info["shell"]);
    }

    private function
getUserEntry($user)
    {
       
$passwd_file = "/etc/passwd";

        if (!
is_file($passwd_file))
            throw new
Exception ("File $passwd_file does not exists");

        if (!
is_readable($passwd_file))
            throw new
Exception ("File $passwd_file cannot be read");

       
$passwd_content = file($passwd_file);

        foreach (
$passwd_content as $entry) {
           
$params = explode(":", $entry);

           
/* We can find by username or by uid: */
           
$search = is_numeric($user) ? $params[2] : $params[0];

            if (
$search == $user)
                return
$entry;
        }

        return
null;
    }

}
?>



PHP4 DirectoryIterator Class
Categories : PHP, PHP Classes, Filesystem, Directories
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
PHP Transfer data from text file to Mysql Table
Categories : PHP, PHP Classes, Filesystem, Databases, MySQL
3 lines of Code to extract Tar, Zip, Gzip etc..
Categories : PHP, Filesystem, PHP Classes, Compression
filesplit : Split big text files in multiple small ones
Categories : PHP, Log Files, Filesystem, PHP Classes
A File Browser Class.To Read Drives,Directories and Files .Files writing is also possible
Categories : PHP, PHP Classes, Filesystem
Remote Archive (Zip, Tar, Gzip) downloader with FTP and local extration support
Categories : PHP, FTP, Filesystem, PHP Classes, Compression
Bs_IniHandler is a class that can read and write ini-style files (and strings)
Categories : PHP, Filesystem, PHP Classes
An efficient iterative and buffered text file reader
Categories : PHP, Classes and Objects, Filesystem, PHP Classes, Log Files
Easy upload class
Categories : PHP Classes, Filesystem, HTTP, PHP
Search and Replace Text : Searches Files for Specified Text and Replaces It by a Given Text
Categories : PHP, PHP Classes, Search, Filesystem
Compare two texts and display a block of text with the differences between them.
Categories : PHP, PHP Classes, Filesystem, Strings, Arrays
Class that allows the PHP developer to create and manage UNIX like password files suitable for use as Apache authentication password files.
Categories : HTTP, PHP, PHP Classes, Filesystem
Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics, PHP, PHP Classes, GD image library, Charts and Graphs
Keep() - maintenance function for backup folders
Categories : PHP, Filesystem, Maintenance