Login System is the First Part of Security system in web programming. In this tutorial I am going to show you the collection of various methos and types of login system. I will give a right choice for your system and you can understand more about login.
An Introduction to Object Oriented PHP

What the heck are Objects and Classes?
Classes, at their simplest point, are just receptacles of functions. They can be compared to a folder on your computer (assuming you aren’t running DOS). Inside the folder you may have three files, or in this case, functions. Let’s use a classic example, a Dog.
Take a look at the following image:

As you can see, a Dog has many “functions”. It can run, walk, sit, play, and bark. This is the essence of what a class is.
An Object, on the other hand, is a way to represent your class. For example, you can have your class named “Dog”, but you can reference it by a variable called Cat if you really wanted to confuse yourself.
That’s all we’re going to cover in this section, so if you’re still confused, read on and I believe the examples will make some coherent sense.
Writing our first class
Since this is just our first class, we’re going to keep things nice and simple. Open up your text editor of choice and make a new file in your web root called myClass.php. Add in the following code:
<?php
class myClass
{
function sayHello()
{
echo "Hello there!";
}
}
?>
If you navigate to this file on your server, nothing will show up. All we did was set up a class (container) and add in a function, we never referenced it to be run.
How to use your freshly written class
Now that we have our myClass.php file all written, we’re going to reference it and use it. Make a new file in the same folder as your class is in, called index.php. Add in the following code:
<?php
require_once('myClass.php');
$myClass = new myClass();
$myClass->sayHello();
?>
If you run the file, you should see “Hello World!” echoed out. Let’s go over what we did to make this work. First, you can see that we required the myClass.php file, which contains our container full of functions. Next, we had to make a new Object, and we used the class name as the object name, just for ease of use. And finally, we referenced our sayHello function by writing the Object name with an arrow and the function name.
Making it Friendlier
Right now, if we wanted to use this to greet a logged in user, there wouldn’t be much of a sense of personalization, would there? Wouldn’t it be nice if we could say Hello to the specific user? Well, we can! Go back to your myClass.php file and edit it accordingly:
<?php
class myClass
{
function sayHello($user)
{
echo "Hello " . $user . "!";
}
}
?>
All we did was add a parameter to the function called name, that we can pass along to the function from our index file. Go back to your index.php file now and add your name like so:
<?php
require_once('myClass.php');
$myClass = new myClass();
$myClass->sayHello('Dixon');
?>
Now, reload your index.php file and you should see a nice textual greeting!
Conclusion
Now that we’ve covered the very basics of Object-Oriented PHP, you can practically do it all. And was it hard? Hopefully not! Be sure to check in later for the rest of this series, in which we’ll be making a fully functional MySQLi Database interaction class! Thanks for reading.
Constructors and Destructors
Think of PHP constructors and destructors like a building. You construct a building at first, then when you’re done using it, you destruct it. Except in PHP, there are no live explosives for the destruction. Let’s look at the following example of constructors:
<?php
class MyClass
{
function __construct()
{
echo "MyClass Loaded!";
}
}
$MyClass = new MyClass();
?>
In this example, we create a new class simply called MyClass, then a constructor function that says MyClass Loaded!. Basically, anything you want to happen when you call upon your class, should go in the constructor function.
In PHP, you don’t need to worry about always having a __destruct() method in your class, as all classes and variables are removed after your object is destroyed. (At the end of execution).
Returning data from your functions
In the real world, you don’t want to be using echo statements within your functions, you want to run your function and return the data for you to echo out where you want it. Let’s take a look at the following example that could be part of a blog application:
<?php
class MyClass
{
var $mysqli;
function __construct()
{
$this->mysqli = new mysqli('localhost', 'root', '', 'blog');
}
function get_latest_posts()
{
//Do some database selection
$query = "SELECT * FROM `posts` ORDER BY `id` DESC";
$result = $this->mysqli->query($query);
return $result;
}
}
?>
Here, we are using a constructor to make a new MySQLi connection, and then using that connection set in the constructor to run a possible query, then to return the result set to be used however you’d like to display the data. Simple, right?
Keeping Organized
In the first part of this series, I described classes as boxes, and functions as the things within the boxes. This picture is a great representation of keeping your classes well separated from each other, and their contents nicely arranged.
One key aspect of writing classes is to keep things easy to read and edit later. Let’s take a look at a file from the very popular blogging platform Wordpress. As you can see, above every variable declaration, class declaration, and function declaration, there is vital information about the parameters, what the function does, and what it returns. Let’s write our own example now:
<?php
/*
* @name MyClass
* @params none
* Our database class that makes a new database connection, and will insert userdata.
*/
class MyClass
{
/*
* MySQLi Connection Link
*/
private $mysqli;
/*
* __construct
* Sets new MySQLi Connection
*/
function __construct()
{
$this->mysqli = new mysqli('localhost', 'root', '', 'buildinternet');
}
/*
* insert_userdata
* @params username, password
* @returns bool
*/
function insert_userdata($username, $password)
{
//Insert the userdata into the database
if(success)
{
return true;
} else {
return false;
}
}
}
php?>
Here, we have said what our class is, what it does, and then defined each function or variable within it. In the insert_userdata() function, we have said what the parameters are and what it returns above the function. As you can already see, these comments help immensely when trying to read your code or trying to find a problem with your code.
Variables and Constructor
Create a new file called class.db.php and insert the following:
<?php
/*
* class db
* @param Host
* @param User
* @param Password
* @param Name
*/
class db
{
var $host; //MySQL Host
var $user; //MySQL User
var $pass; //MySQL Password
var $name; //MySQL Name
var $mysqli; //MySQLi Object
var $last_query; //Last Query Run
/*
* Class Constructor
* Creates a new MySQLi Object
*/
function __construct($host, $user, $pass, $name)
{
$host = $this->host;
$user = $this->user;
$pass = $this->pass;
$name = $this->name;
$this->mysqli = new mysqli($this->host, $this->user, $this->pass, $this->name);
}
}
$db = new db('localhost', 'root', '', 'blog');
?>
**Try and dissect what we have done here before reading the explanation!**
First, we have done the most important part of Object Oriented PHP – organization! We have said what the class name is, and all the parameters that need to be passed to it when it is loaded. Next, inside the class, we have defined our four variables for MySQL connection and then required them as parameters of the constructor function, which can be passed when the class is loaded at the bottom of the file. Next, we have set our $mysqli variable to a new MySQLi Object. Simple, right? Let’s move on.
Main Functions
SELECT
Now that we have the connection down, we can start working with the database. Add a select function like this:
/*
* Function Select
* @param fields
* @param from
* @param where
* @returns Query Result Set
*/
function select($fields, $from, $where)
{
$query = "SELECT " . $fields . " FROM `" . $from . "` WHERE " . $where;
$result = $this->mysqli->query($query);
$this->last_query = $query;
return $result;
}
Here we have made a select function for selecting data from a MySQL table. We have defined three parameters, and you can see how they fit into the final query. All we return from this function is a query result set, which you can work with however you like in your pages.
INSERT
Of course, we can select data with our class now, but we don’t have anything to select unless we insert it! Let’s do that now by adding this function to your class:
/*
* Function Insert
* @param into
* @param values
* @returns boolean
*/
function insert($into, $values)
{
$query = "INSERT INTO " . $into . " VALUES(" . $values . ")";
$this->last_query = $query;
if($this->mysqli->query($query))
{
return true;
} else {
return false;
}
}
Another quite simple function, we are just requiring two parameters: the table name to insert the data into, and the values for the fields. Instead of returning any real data for this function, we just go ahead and run it and if it inserted the data, it returns true, and if not, false. Simple for inserting data.
DELETE
Now that we can insert and then select our data, we have to have a way to delete it say if a user wanted to delete their account. Add this function:
<?php
/*
* Function Delete
* @param from
* @param where
* @returns boolean
*/
function delete($from, $where)
{
$query = "DELETE FROM " . $from . " WHERE " . $where;
$this->last_query = $query;
if($this->mysqli->query($query))
{
return true;
} else {
return false;
}
}
?>
Some extra goodies
You probably noticed the last_query variable we defined at the beginning of the class, then we set it every time we ran a query in a function. This is very vital for troubleshooting, to see what’s wrong with your query. Another possible class variable could be a last_error, that would hold the last error returned.
Thanks to BuildInternet
Original Source From: http://buildinternet.com/
25 Awesome web design/development + graphics/UI+resources/tutorial sites
There are lots of design/developer tutorial sites with lots of collection of resources and much more. Here are some of the best sites which designer’s should visit. You will get lots of collection of resources from the sites.
1. Smashing Magazine
2. noupe
3. TutsPlus
Tuts+ having great collection of resources related to audio, UI design and much more.
4. Six Revisions
5. Design Follow
6. Design Mag
7. Blogfreakz
8. CreativeOverflow
9. Denbagus
10. Extra Tuts
11. PSD Vault
12. Smashing Buzz
13. Tutorial Lounge
14. Wordpress Arena
15. Design Ussion
16. Psdeluxe
17. Designtutorials 4u
18. Perishable Press
19. Artfans Design
20. Inspire Bit
21. Design Dazzling
22. Tutorials Palace
23. Web and Designers
24. Out Law Design Blog
25. Designrfix
CSS Positioning, Layout and Understanding CSS z-index
Layout with CSS is a great way to manage Objects and elements in a web page and a very easy. I think css is better than the tabural stracure. In a CSS styles you need to look at each part of the page as an individual chunk that you can shove wherever you choose. You can place these chunks absolutely or relative to another chunk using CSS. One of the major benefits of using CSS is that you’re no longer forced to lay your sites out in tables.
The position property is used to define whether an element is absolute, relative, static or fixed. This is the fun part. Using CSS you can define the position for your id’ed divs. Store your position information in a style call like this:
For Example
#banner {
position: absolute;
margin:5px 5px 0px 0px //Defines Top, right, bottom and left margin
}
#content {
margin-left: 20em;
}
#div-1 {
position:static;
}
position:static
The default positioning for all elements is position:static, which means the element is not positioned and occurs where it normally would in the document.
Normally you wouldn’t specify this unless you needed to override a positioning that had been previously set.
#divname{
position:static;
}
position:relative
If you specify position:relative, then you can use top or bottom, and left or right to move the element relative to where it would normally occur in the document.
#divname {
position:relative;
top:20px;
left:-40px;
}
position:absolute
When you specify position:absolute, the element is removed from the document and placed exactly where you tell it to go.
#divname {
position:absolute;
top:0;
right:0;
width:200px;
}
position:relative + position:absolute
If we set relative positioning on first div, any elements within first div will be positioned relative to first div. Then if we set absolute positioning on second, we can move it to the top right of first div:
#firstdiv {
position:relative;
}
#seconddiv {
position:absolute;
top:0;
right:0;
width:200px;
}
Floating an element will shift it to the right or left of a line, with surrounding content flowing around it. For variable height columns, absolute positioning does not work, so let’s come up with another solution.
We can “float” an element to push it as far as possible to the right or to the left, and allow text to wrap around it.
#divname {
float:left;
width:200px;
}
Then after the floating elements we can “clear” the floats to push down the rest of the content.
#divclear{
clear:both;
}
What is z-index
When you’re using CSS positioning to position elements on the page, you need to think in virtual 3-D. Each element on the page can be layered on top or beneath any other element. The z-index determines where in the stack each element is. I like to think of the elements as pieces of paper, and the Web page is a collage. Where I lay the paper is determined by positioning, and how much of it shows through the other elements is the z-index.
img
{
position:absolute;
left:0px;
top:0px;
z-index:-1;//Set behind of any element while the z-index is -1.
}
On short note z-index is used to stack order of an element.
PHP Image File Upload Tutorial
In this tutorial you will learn to upload image file using PHP. Together you will learn to restrict file type. In this tutorial I am showing you example in which you can upload only jpg/jpeg images. It a very easy method I am going to show you and hope you will understand.
Start With Form :
<form action="" method="post" enctype="multipart/form-data" name="form1"><p>
<input name="fileImage" type="file" id="fileImage">
</p><p>
<input name="save-image" type="submit" id="save-image" value="Upload Image">
</p>
</form>
Upload Code:
<?phpif(isset($_POST['save-image'])){//Line Use to check if the buttton was pressed.
$fileName=$_FILES['fileImage']['name'];
//Getting file name and assigning it to $fileName variable
$fileType=$_FILES['fileImage']['type'];
//Getting file type and assigning it to $filetype variable
$fileSize=$_FILES['fileImage']['size'];
//Getting file size and assigning it to $filesize;
$tmpName=$_FILES['fileImage']['tmp_name'];
//Getting temporary name of file and assigning it to $tmpName
$maxsize=1048576;
//Defining maximum file size to 1Mb
$uploadDir="upload/";
//Define upload directory
$filePath=$uploadDir.$fileName;
//Defining file path so that we can use it on move_uploaded_file function
if(($fileType=="image/jpg") || ($fileType=="image/jpeg") || ($fileType=="image/pjpeg")){
//Checking file type. Is the file jpg or not?
$result=move_uploaded_file($tmpName, $filePath);
//When file is jpg moving file to the upload directory from temp directory
}
if($result){
//If file move successfully then show message
echo "File Uploaded Successfully";
}else{
//If file is invalid display message
echo "Invalid File Format";
}
}
?>
Full Code:
<?phpif(isset($_POST['save-image'])){$fileName=$_FILES['fileImage']['name'];
$fileType=$_FILES['fileImage']['type'];
$fileSize=$_FILES['fileImage']['size'];
$tmpName=$_FILES['fileImage']['tmp_name'];
$maxsize=1048576;
$uploadDir="upload/";
$filePath=$uploadDir.$fileName;
if(($fileType=="image/jpg") || ($fileType=="image/jpeg") || ($fileType=="image/pjpeg")){
$result=move_uploaded_file($tmpName, $filePath);
}
if($result){
echo "File Uploaded Successfully";
}else{
echo "Invalid File Format";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Upload Image</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" name="form1">
<p>
<input name="fileImage" type="file" id="fileImage">
</p>
<p>
<input name="save-image" type="submit" id="save-image" value="Upload Image">
</p>
</form>
</body>
</html>
Featured Articles
31 Grunge WordPress Theme...
Grunge design is most popular among designers, it's have been trend in wordpress [+]
Top WordPress Themes from TOPWPTHEMES...
1. Unistar Features:2 Columns, Adsense Ready, By Zinruss, Fixed Width, Left Sidebar, WP Themes, Widget Ready Download [+]
Adsense Ready Wordpress Themes...
Using a WordPress theme with distinct ad blocks and optimized ad placements will very likely [+]
Top Ten Real Estate Theme from Themes Ju...
Today I was looking for some Real Estate WordPress Theme. I found site Taree Internet [+]
Archives
-
Recent Posts
Recent Articles
- 10 Simple PHP Login Sytem Tutorial
- An Introduction to Object Oriented PHP
- 25 Awesome web design/development + graphics/UI+resources/tutorial sites
- CSS Positioning, Layout and Understanding CSS z-index
- PHP Image File Upload Tutorial
- jQuery addClass(), removeClass(), toggleClass() Tutorial
- Understanding Search Engine Models
- Inspiration Windows 7 Wallpapers
- JavaScript Built in Object, Method, Properties & Handling Events in browser
- How to Create a MovieClip Rotating around the Center Continiously
Popular Tags
- 3 columns 125x125 Advertising-Ready Action Script Adsense Adsense Ready Ajax comments CSS Download download icons Flash free icons free themes Icons Inspiration JavaScript Jquery jquery slideshow magazine themes Manage Comments navigations Photoshop php Plugins rss rss icons set SEO SEO Expert SEO Plugins SEO Tips spam spam protection theme Themes twitter icons Wallpaper web 2.0 wordpress WordPress Code wordpress contents in other pages WordPress How-To wordpress theme wordpress themes Word Press Tips WP-Hacks
Recent Feedbacks
- Shahriar Hyder: Very nice article mate. I have also linked to yours from my blog post below where I am trying to...
- neo: I would be better if you should add button “next” and “prev”..
- cheap phenteramine: This is certainly the best that I read today in the Internet
- Bill Bartmann: Excellent site, keep up the good work
- Bill Bartmann: Hey good stuff…keep up the good work!
Most Commented
- Display Wordpress content outside of your blog (15)
- Top 10 Magazine WordPress Themes from Premiumthemes (9)
- WordPress Meta-Tags Plugin (4)
- Simple JQuery Image Slide Show with Semi-Transparent Caption (4)
- Web 2.0 and SEO (3)
- Photoshop Tutorial Sites (2)
- How to: Embed Google Ad in your post (2)
- Wordpress Tips and Tricks (2)
- Digital Photography Tutorial and Tips (2)
- Useful Wordpress Tricks to Make Your Theme Even Better (2)

RSS Feeds
Feed Comment 




























