Free articles
Google
Web www.media13.com


Media13.com is a source of free to republish or reprint articles, writers may submit your articles in our database as long so you agree that your article will be freely republish or reprint by other.


Submit Article

Search our database

Received article from us.

Name

Email Address

Friends

Bollywood News
Link building
Article submission service
Freelance Writers
Laser hair removal

We have been looking for freelance writers. Contact us

 


Developing State-enabled Applications With PHP   by John L






Installment 1

Developing State-enabled Applications With PHP

When a user is browsing through a website and is surfing from one web page to another, sometimes the website needs to remember the actions (e.g. choices) performed by the user. For example, in a website that sells DVDs, the user typically browses through a list of DVDs and selects individual DVDs for check out at the end of the shopping session. The website needs to remember which DVDs the user has selected because the selected items needs to be presented again to the user when the user checks out. In other words, the website needs to remember the State - i.e. the selected items - of the user`s browsing activities.

However, HTTP is a Stateless protocol and is ill-equipped to handle States. A standard HTML website basically provides information to the user and a series of links that simply directs the user to other related web pages. This Stateless nature of HTTP allows the website to be replicated across many servers for load balancing purposes. A major drawback is that while browsing from one page to another, the website does not remember the State of the browsing session. This make interactivity almost impossible.

In order to increase interactivity, the developer can use the session handling features of PHP to augment the features of HTTP in order to remember the State of the browsing session. The are basically 2 ways PHP does this:


1. Using cookies


2. Using Sessions

The next installment discusses how to manage sessions using cookies...

Installment 2

Cookies

Cookies are used to store State-information in the browser. Browsers are allowed to keep up to 20 cookies for each domain and the values stored in the cookie cannot exceed 4 KB. If more than 20 cookies are created by the website, only the latest 20 are stored. Cookies are only suitable in instances that do not require complex session communications and are not favoured by some developers because of privacy issues. Furthermore, some users disable support for cookies at their browsers.

The following is a typical server-browser sequence of events that occur when a cookie is used:


1. The server knows that it needs to remember the State of browsing session


2. The server creates a cookie and uses the Set-Cookie header field in the HTTP response to pass the cookie to the browser


3. The browser reads the cookie field in the HTTP response and stores the cookie


4. This cookie information is passed along future browser-server communications and can be used in the PHP scripts as a variable

PHP provides a function called setcookie() to allow easy creation of cookies. The syntax for setcookie is:


int setcookie(string name, [string val], [int expiration_date], [string path], string domain, [int secure])

The parameters are:


1. name - this is a mandatory parameter and is used subsequently to identify the cookie


2. value - the value of the cookie - e.g. if the cookie is used to store the name of the user, the value parameter will store the actual name - e.g. John


3. expiration_date - the lifetime of the cookie. After this date, the cookie expires and is unusable


4. path - the path refers to the URL from which the cookie is valid and allowed


5. domain - the domain the created the cookie and is allowed to read the contents of the cookie


6. secure - specifies if the cookie can be sent only through a secure connection - e.g. SSL enable sessions

The following is an example that displays to the user how many times a specific web page has been displayed to the user. Copy the code below (both the php and the html) into a file with the .php extension and test it out.

[?php


//check if the $count variable has been associated with the count cookie


if (!isset($count)) {


$count = 0;


} else {


$count++;


}


setcookie(`count`, $count, time()+600, `/`, ``, 0);


?]

[html]


[head]


[title]Session Handling Using Cookies[/title]


[/head]


[body]


This page has been displayed: [?=$count ?] times.


[/body]


[/html]

The next installment discusses how to manage sessions using PHP session handling functions with cookies enabled...

Installment 3

PHP Session Handling - Cookies Enabled

Instead of storing session information at the browser through the use of cookies, the information can instead be stored at the server in session files. One session file is created and maintained for each user session. For example, if there are three concurrent users browsing the website, three session files will be created and maintained - one for each user. The session files are deleted if the session is explicitly closed by the PHP script or by a daemon garbage collection process provided by PHP. Good programming practice would call for sessions to be closed explicitly in the script.

The following is a typical server-browser sequence of events that occur when a PHP session handling is used:


1. The server knows that it needs to remember the State of browsing session


2. PHP generates a sssion ID and creates a session file to store future information as required by subsequent pages


3. A cookie is generated wih the session ID at the browser


4. This cookie that stores the session ID is transparently and automatically sent to the server for all subsequent requests to the server

The following PHP session-handling example accomplishes the same outcome as the previous cookie example. Copy the code below (both the php and the html) into a file with the .php extension and test it out.

[?php


//starts a session


session_start();

//informs PHP that count information needs to be remembered in the session file


if (!session_is_registered(`count`)) {


session_register(`count`);


$count = 0;


}


else {


$count++;


}

$session_id = session_id();


?]

[html]


[head]


[title]PHP Session Handling - Cookie-Enabled[/title]


[/head]


[body]


The current session id is: [?=$session_id ?]


This page has been displayed: [?=$count ?] times.


[/body]


[/html]

A summary of the functions that PHP provides for session handling are:


1. boolean start_session() - initializes a session


2. string session_id([string id]) - either returns the current session id or specify the session id to be used when the session is created


3. boolean session_register(mixed name [, mixed ...]) - registers variables to be stored in the session file. Each parameter passed in the function is a separate variable


4. boolean session_is_registered(string variable_name) - checks if a variable has been previously registered to be stored in the session file


5. session_unregister(string varriable_name) - unregisters a variable from the session file. Unregistered variables are no longer valid for reference in the session.


6. session_unset() - unsets all session variables. It is important to note that all the variables remain registered.


7. boolean session_destroy() - destroys the session. This is opposite of the start_session function.

The next installment discusses how to manage sessions using PHP session handling functions when cookies are disabled...

Installment 4

PHP Session Handling - Without Cookies

If cookies are disabled at the browser, the above example cannot work. This is because although the session file that stores all the variables is kept at the server, a cookie is still needed at the browser to store the session ID that is used to identify the session and its associated session file. The most common way around this would be to explicitly pass the session ID back to the server from the browser as a query parameter in the URL.

For example, the PHP script generates requests subsequent to the start_session call in the following format:


http://www.yourhost.com/yourphpfile.php?PHPSESSID=[actual session ID]

The following are excerpts that illustrate the discussion:

Manually building the URL:


$url = `http://www.yoursite.com/yourphppage.php?PHPSESSID=` . session_id();


[a href=`[?=$url ?]`]Anchor Text[/a]

Building the URL using SID:


[a href=`http://www.yoursite.com/yourphppage.php?[?=SID ?]`]Anchor Text[/a]



Author Info:

This PHP scripting article is written by John L. John L is the Webmaster of The Ultimate BMW Blog! (http://www.bimmercenter.com).

The Ultimate BMW Blog!


Latest 20 articles

Why Should I Hire a Seattle Real Estate Attorney? In every real estate transaction there are a wide variety of legal issues that must be taken care of. Contracts should always be reviewed by an attorney who understands the nuances of real estate law. But there are also state specific State laws to contend with. A Seattle real estate lawyer deals with a large number of State legal issues related to acquiring, financing, developing, managing, co

California IT Professionals – In Need of California Class Action Attorneys! It is hard to miss the wave of California wage and hour litigation related to California IT professionals and Computer employee overtime that has been sweeping California recently. Even the largest software and computer companies have paid out millions of dollars to employees wrongfully classified as “exempt”, or in other words, not entitled to overtime. A layperson would believe that with pr

Protect Your Mental Health With A Payday Loan Just when you thought that things couldn’t get any worse, more banks went under. More countries are declaring economic crisis. It seems that the world’s financial problems are bound to get worse. Even if you do not have considerable investments in various banks, I am sure that you are feeling the stress that results from these economic upheavals. I sure am. I am just an average person, with a

Free Bulk SMS services People are getting very busy these days without having enough time to talk unless it is very important. Mobile SMS have supported this need to contemporary times as now people do not want to call and enter in the unproductive conversation before coming up to the actual issue. SMS provides you the benefit to come straight to the point and also saves money. What if you get this totally free?

HELP – I Have IRS Levy Problems! If IRS collection notices are ignored, the IRS is forced to collect from taxpayers by force. They do this with their dreaded IRS levy. By law, the IRS has the right to levy bank accounts (IRS bank levy), garnish your paychecks (IRS wage levy), or even seize your assets. But you do not have to let the IRS bully you or your family. There are ways to stop an IRS levy. The first step is to know the

Why Use Professional Tax Debt Help? Good IRS tax relief is hard to find and for people with complicated tax issues, it is an absolute necessity. But how do you know which tax reduction firm is the best one to try? How can you be sure you're going to get the tax debt help that you need? And why is it so vital to receive help from professionals? Settling Your IRS Tax Debt For Less When your IRS tax debt is spiraling out

IRS Settlement – Can You Really Settle Your IRS Tax Debt for Less? It's possible to settle your IRS tax debt, but it presents a challenge. Proving you can settle your tax debt for less is a daunting experience. You have to contend with pages of IRS paperwork rife with technical terms. Settling tax debt is indeed a reality and it can be done. However, there's a lot you need to know before you attempt to settle your IRS tax debt. Rebuking the Lies - The

IRS Tax Relief – The Most Popular IRS Tax Relief Solutions Tax law provides many solutions for resolving tax debt. But if you were to contact the IRS directly, they would only alert you to one solution, and that's paying the tax debt in full. Here are five popular IRS tax relief solutions you should know about to be more informed. IRS Tax Settlement It is possible to settle your IRS tax debt. But there are some pitfalls you need to know. Fi

Hire the California Labor Board or California Labor Law Attorneys - You Decide With a downturn in the economy, many employers are cutting back on payroll. Unfortunately, some employers are reducing payroll costs by violating the California overtime laws. When this occurs, employees have essentially two options to recover their California overtime pay: the California labor board, or hiring California labor law attorneys. Although the California Labor Board is a commonly

Hiring a Car At Bangalore - Is More of Necessity Than A Luxury Your sedan is probably the best materialistic thing that you own and while going to a new place, that is what you ought to miss the most but if you are going to Bangalore then you probably have a option of getting a replacement so that you don’t miss it all that most because it will be as comfortable and as obedient as your own car and the Bangalor

How to Choose a Car Rental Company in Bangalore Bangalore is a place that lists one of the best as far as infrastructure is considered in India as it is the IT hub of India and thus the roads to drive is atmost pleasure and thus if Bangalore is the destination that you are planning for next then the best way to move around is by hiring a car. To hire is car is very simple if it is in Bangalore because there are some very good car rental compani

Car Rental Companies in Bangalore If you are travelling to Bangalore and hiring a car is what worrying you then you can be relaxed because this is one service that you will easily get in Bangalore and that too at very affordable and economic prices. Basically there are really good car rental companies in Bangalore available for renting the cars and you can either book in advance or go there and hire a car for yourself. Also, you h

Tips to Hire a Car in Bangalore One thing that most of us agree is that the fact that the most comfortable way to move around at any place is by your own vehicle but what if you are going to a new place, it is not possible to carry your vehicle along with you and you actually cannot trust too much on the public transportation system and at such situation the best possible option is to hire a car for yourself, at some places it c

Hire a Car: Comfortable Way to explore Bangalore If you are out to a new place than the first thing that comes into your mind is a comfortable accommodation and then the second one on the priority list is a comfortable way to move around in the city and if Bangalore is your preferred location, than you’ll be having options for both of the facilities, but if we specifically speak about the second one that is moving comfortably than the best opti

Car Rental – A convenient mode of transport in Bangalore Bangalore, a place which probably is considered one of the best places in India as far as infrastructure is considered and reasons are many for that, one is because of the IT hub that it is and also because it is one of very good places if you are considering holidays and because of this very good facility provided for the people visiting Bangalore is that you have many options in case if you are

Rent a Car in Bangalore: Take the Right Decision In today’s world, time is money; the more you save it better it is for you. And in that case if you are going to another place where you are not too familiar with the surroundings, then instead of wasting time on travelling by locating and travelling by public transport is to hire a vehicle for yourself. This helps in many ways, one it saves on time and also it moves at your pace so you don’t have

Bangalore Car Rental: Save Your Time When you are at an unknown place or for that matter known place and time is your major factor of concern then, the best way to save on time is by having your own vehicle for conveyance. This gives you freedom to move at your own pace and wish. And for that matter if you are at a place like Bangalore where the roads are so beautiful that it is a sheer pleasure to travel through your own rented vehi

Best Package Tours to Kerala Kerala – God’s own country which means heaven for those who appreciate the real untouched, naïve beauty of nature and if you are one of those than consider Kerala as the option for you next holiday. Kerala gives an option to explore the nature to the fullest because it has all the places where you can explore the nature be it scenic beaches or the hill stations or the ethnic culture, just everythi

Kerala Tour: A Getaway from Regular Stress If you are tired of daily stress and meetings and looking for a getaway so that you snatch some time for yourself with your loved one’s than Kerala holidays is the perfect is the perfect thing for you. Its calmness and closeness to nature would give you that much needed peace of mind that you always wanted. Also along with enjoying the beauty of this scenic place on your holidays to Kerala you can

Kerala Tour Packages: Have A Look If holidays are on your mind, then Kerala is one option that you cannot choose to neglect. Because Kerala is one place that offers you all from calm and serene natural places to exciting sports to exotic beaches and also beautiful hill stations, everything provided at one place which is also known as god’s own country. And obviously such wide range of activities would make it a tough job to cover

Categories
Acne
Advertising
Advice
Aerobics-Cardio
Affiliate Programs
Alternative
Arts
Attraction
Auctions
Audio-Streaming
Autos
Awards
Babies-Toddler
Beauty
Blogging-RSS
Book-Marketing
Branding
Breast-Cervical-Ovarian-Cancer
Broadband-Internet
Build-Muscle
Business
Cancer
Careers-Employment
Casino-Gambling
CGI
Coaching
Coffee
College-University
Colon-Rectal-Cancer
Communications
Computers
Cooking-Tips
Copywriting
Crafts-Hobbies
Creativity
Credit
Cruising-Sailing
CSS
Currency-Trading
Customer-Service
Dating
Debt-Consolidation
Debt-Relief
DHTML
Diabetes
Direct Mail
Divorce
Domain Names
EBooks
ECommerce
Education
Elder-Care
Email-Marketing
Email Entertainment
Entrepreneurialism
Environment
Exercise
Ezine-Marketing
Ezine-Publishing
Family
Finance
Fishing
Fitness
Food
Free
Games
Gardening
Goal-Setting
Golf
Government
Grief-Loss
Hair-Loss
Happiness
Hardware
Health
Hobbies
Holidays
Home-Security
Homes
Home Business
Home Repair
HTML
Humanities
Humor
Innovation
Inspirational
Interior-Decorating
Internet-Marketing
Javascript
Kids And Teens
Landscaping-Gardening
Law
Leadership
Leases-Leasing
Legal
Leukemia
Link Popularity
Loans
Lung-Cancer
Lymphoma-Cancer
Management
Marketing
Marriage-Wedding
Martial-Arts
Medicine
Meditation
Men's-Issues
Metaphysical
MLM
Mobile-Cell-Phone
Mortgage-Refinance
Motivational
Multimedia
Music
Negotiation
Network-Marketing
Networking
News-and-Society
Newsletters
Nutrition
Off-Line Promotion
Online Business
Online Promotion
Organizing
Other
Outdoors
Page Rank
Parenting
Personal-Tech
Pets
Photography
Podcasting
Poetry
Politics
Positive-Attitude
PPC-Advertising
Presentation
Prostate-Cancer
Psychology
Public-Speaking
Publishing
Real-Estate
Recipes
Recreation
Reference
Relationships
Religion
Sales
Sales-Management
Sales-Teleselling
Sales-Training
Satellite-Radio
Satellite-TV
Scams
Science
Security
Self Help
Self Improvement
Sexuality
SE Optimization SE Positioning
SE Tactics
Shopping
Site-Promotion
Site Security
Skin-Cancer
Small-Business
Social Issues
Society
Software
Spam
Spirituality
Sports
Stocks-Mutual-Funds
Strategic-Planning
Stress-Management
Structured-Settlements
Success
Supplements
Taxes
Team-Building
Technology
Teleseminars
Time-Management
Traffic-Building
Traffic Analysis
Travel
Uterine-Cancer
Vacation-Rentals
Video-Conferencing
Video-Streaming
Viral Marketing
VOIP
Web-Development
Webmasters
Web Design
Web Hosting
Weight Loss
Wine-Spirits
Women
Writing
Yoga

Copyright © media13.Com  2005. All Rights Reserved.

Sources : SEO India - Internet web directory