Showing posts with label beginners. Show all posts
Showing posts with label beginners. Show all posts

Saturday, May 21, 2011

PHP: Cookies


A cookie is a message given to a Web browser by a Web server. The browser stores the message in a small text file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, the cookie is sent back to the server too.
There are a wide variety of things you can do with cookies. They are used to store information about user, visited pages, poll results and etc. The main purpose of cookies is to identify users and possibly prepare customized Web pages for them.
  • How to Create a Cookie?
  • How to Retrieve a Cookie Data?
  • How to Delete a Cookie?
Normally cookies are used only to store small amounts of data. Websites can read the values from the cookies and use the information as desired. In addition to the information it stores, each cookie has a set of attributes that helps ensure the browser sends the correct cookie when a request to a server is made.
Even though cookies are not harmful some people do not permit cookies due to concerns about their privacy. In this case you have to use Sessions.

Friday, May 6, 2011

PHP Session - Starting Session, Modifying Session and Deleting Session

In the context of PHP, a "session" is the time that a user spends on a web site. Users may view many other Web pages between the time they enter this particular site and then leave it. Often, information for the complete session is very desirable. Beginning with version 4.0, PHP provides a way to do this.

A PHP Session allows certain data to be preserved across an access span, by assigning a unique ID called "Session ID", to each visitor to the site. This Session ID can be stored as a cookie at the client end, or passed through a URL. A PHP Session also enables the registration of arbitrary numbers of variables to be preserved across requests.
PHP allows a session to be set up and session variables to be stored. After the session is created, session variables are available to the page visitor on other pages. To make this session information available, PHP does the following:
  • PHP assigns a session ID number.
  • The number is a really long alphanumeric number that is unique to the user and that cannot possibly be guessed by anyone else. The session ID is stored in a PHP system variable named PHPSESSID.
  • PHP stores the variables to be saved for the session in a file on the server.
  • The file is named with the session ID number. It is stored in a directory specified by session.save_path in the php.ini file. The session directory must exist before session files can be saved in it.
PHP passes the session ID number to every page.
If the user has cookies turned on, PHP passes the session ID by using cookies. If the user has cookies turned off, the session can also be tracked by passing PHPSESSID as a GET variable to every page that participates in that session.
PHP gets the variables from the session file for each new session page.
Whenever a user opens a new page that is part of the session, PHP gets the variables from the file by using the session ID number that was passed from the previous page. The variables are available in the $_SESSION array.

Thursday, May 5, 2011

PHP Cookies - Explaing PHP Cookie with example

In the course of developing highly interactive web sites it is necessary to deal with large amount of data flow between client browswer and web server. It is quite cumbersome handling such large amount of data using hidden fiels in HTML forms. This problem can be overcomed by using HTTP cookies. HTTP cookies are the bunch of data/text sent by the server to the web browswer. Web browser store this data locally and send back to the server each time it accesses the server before it expires. Note that now a days Most browsers allow users choice to accept cookies or not, sometime rejection causes web site to not work properly.

setcookie() function.
This function in PHP Language is used to work with HTTP cookies. setcookie() defines a cookie to be sent along with the rest of the HTTP headers. This must be called before sending any output to the browser because cookies are part of the HTTP header. On successful it will return TRUE. But this does not mean that client browser has ccepted cookie.

Saturday, April 30, 2011

PHP Simple HTML DOM Parser - an Intoduction

PHP Simple HTML DOM Parser, is one of the easiest DOM manipulation script written in PHP5+. Being Open source, it is free to use under the MIT License. Supporting invalid HTML, this parser is better then other PHP scripts that use complicated regexes to extract information from web pages. It helps to find tags on an HTML page with selectors just like jQuery.

Some of the Usage examples are:

Monday, April 25, 2011

File Upload via CURL in PHP

Most of us must have used CURL in PHP, But have you uploaded file using it. If not I must say it is very easy .

Here is the simplest way to upload the file via CURL.

Tuesday, April 19, 2011

Image resize and thubnail with PHP - functions

As websites are getting more and more feature enabled and fully loaded with the multimedia, the need of managing the media like, Music, Images, Videos is increasing day by day. One of the most used media is Images. Image gallerias, Slideshows, light-boxes are common every site. Each of this task is going to need the image resize or creating smaller thumbnails to display. So here is a small function with which you can easily create thumbnails from the image. The following function can resize and crop the image dimensionally or just creating a perfect square.

Monday, April 18, 2011

The difference between the "isset", "empty" and "is_null"

Most the times I have noticed the beginners are confused in testing the variable, whether it contains some data or not. Most of the time these checks fail as the wrong function is being used to assert the correct value. While it is important to be checking values, it is equally important to understand the difference between the different methods of checking and testing values for empty, null, or if they are set.

The following difference chart between "isset", "empty" and "is_null" will be quite helpful for everyone.

Sunday, April 17, 2011

PHP Tutorial for Beginners - by Webmonkey

Just found a great PHP tutorial for Beginners at Webmonkey. It is indeed a very well written and explained tutorial for the beginners who are completely new to PHP. It covers almost everything Basic syntax, Variables, HTML Forms, Arrays, Loops, Functions and lot more.

Read it here

Enjoy reading it. Thanks.