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.

Saturday, May 14, 2011

What is an IDE

In short, an IDE provides a one-stop shop for your coding work. An IDE contains an editor in which you can edit the code, debug the code, view your code in a browser (often embedded), and check in and out of source code control. To support that functionality, an IDE has a set of features you don't find in a basic editor, such as Notepad or Vim. Again, you can extend editors to do a lot of these things, but IDEs have all this functionality in one tidy package -- typically preconfigured:

Projects
A key distinguishing feature of an IDE is that it looks at a PHP application as a project, not just a set of files. That containing concept -- the project -- maintains extra information, such as the configuration of the source code control, the database settings for debugging purposes, and the location of certain key directories.

Debugging
Another handy feature is integrated debugging. With this functionality, you can set breakpoints in the editor at which the PHP interpreter stops during execution of the script. From there, you can inspect the values of local variables to diagnose issues in the code. It's a healthy alternative to sprinkling echo statements through your code to check values or using the error log to get the values of variables.

Email sending Via PHP - Text and HTML

Email is the most popular Internet service today. A plenty of emails are sent and delivered each day. The goal of this tutorial is to demonstrate how to generate and send emails in PHP.

So, you want to send automated email messages from your PHP application. This can be in direct response to a user's action, such as signing up for your site, or a recurring event at a set time, such as a monthly newsletter. Sometimes email contains file attachments, both plain text and HTML portions, and so on. To understand how to send each variation that may exist on an email, we will start with the simple example and move to the more complicated.
  1. Sending TEXT email with PHP
  2. Sending HTML email with PHP 
    Note that to send email with PHP you need a working email server that you have permission to use: for Unix machines, this is often Sendmail; for Windows machines, you must set the SMTP directive in your php.ini file to point to your email server.

    Friday, May 6, 2011

    PHP - Session Security, Tips to keep the session secure

    As Explained in earlier post about the PHP Session - Starting Session, Modifying Session and Deleting Session,session stores important information. Most of the times Session have very important information about the user. User data, like Id, username, and many more.
    Session might also have the Shopping Cart information. All these information are very valuable and sensitive. So proper methods are need to implemented to keep the session secure.

    Here are some of the ways you can keep your session safe.

    1. Use SSL when authenticating users or performing sensitive operations.
    2. Regenerate the session id whenever the security level changes (such as logging in). You can even regenerate the session id every request if you wish.
    3. Have sessions time out
    4. Don't use register globals

    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.

    Monday, May 2, 2011

    Creating a Word Density Checker Function - PHP

    I was looking for some help of writing my keyword density checker class and found this function and it is worth sharing. Have a look at it.


    Function Code for calculating the word density goes as Follows: