Monday, September 14, 2009

PHP cookies

A cookie is used for identification purposes. It is more commonly used to identify a user in a session. It is a small file the application inserts on the users computer. With PHP one can create and retrieve the cookie.

Cookies in PHP can be set using the setcookie() function. This must appear before the HTML tag.
Syntax:
Setcookie(name, value, expire, path, domain);

The cookie that is set can be retrieved as shown below:
Echo $_cookie[“user”];

Cookies can be deleted either by the client or by the server. Clients can easily delete the cookies by locating the Cookies folder on their system and deleting them. The Server can delete the cookies in two ways:
1. Reset a cookie by specifying expiry time
2. Reset a cookie by specifying its name only

Persistent Cookie
Cookies are used to remember the users. Content of a Persistent cookie remains unchanged even when the browser is closed. ‘Remember me’ generally used for login is the best example for Persistent Cookie.

Thursday, September 10, 2009

Mail Function : mail( )

Mail function can be used in several ways, eg a contact form and auto-senders suitable for confirming registration.
Ok the function is used like this:

mail($to, $subject, $message, $headers);
Although its preferred to use variables because its easier to use and modify later.

To make sure the message was sent correctly you can use the following "if block"

if(mail($to,$subject,$message,$headers)){
echo "Email Sent";
}else{
echo "Email Sending Failed";
}

hope this is helpful and makes the mail() function clear and easier to use.

Date Function- Date()

This is a very good function that can be used to date anything from last login to date adding a specific post. It is used in PHP 4 and 5. It is a relatively easy function to use because it goes like this:

date("parameters");

you can also easily format time so this:

date('l dS \of F Y h:i:s A');

I hope you find this helpful

Friday, September 4, 2009

Welcome to PHP Smart Code

PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. Its syntax draws upon C, Java, and Perl, and is easy to learn. The main goal of the language is to allow web developers to write dynamically generated web pages quickly, but you can do much more with PHP.