PHP stands for PHP Hypertext Preprocessor.
Taken directly from PHP's home, PHP.net, "PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly. This is generally a good definition of PHP. However, it does contain a lot of terms you may not be used to. Another way to think of PHP is a powerful, behind the scenes scripting language that your visitors won't see. When someone visits your PHP webpage, your web server processes the PHP code. It then sees which parts it needs to show to visitors(content and pictures) and hides the other stuff(file operations, math calculations, etc.) then translates your PHP into HTML. After the translation into HTML, it sends the webpage to your visitor's web browser.
PHP - What's it do?
It is also helpful to think of PHP in terms of what it can do for you. PHP will allow you to:
• Reduce the time to create large websites.
• Create a customized user experience for visitors based on information that you have gathered from them.
• Open up thousands of possibilities for online tools. Check out PHP - HotScripts for examples of the great things that are possible with PHP.
• Allow creation of shopping carts for e-commerce websites.
What You Should Know
• HTML - Know the syntax and especially HTML Forms.
• Basic programming knowledge - This isn't required, but if you have any traditional programming experience it will make learning PHP a great deal easier.
• Basic programming knowledge - This isn't required, but if you have any traditional programming experience it will make learning PHP a great deal easier.
PHP Cookies - Background
Cookies
have been around for quite some time on the internet. They were
invented to allow webmaster's to store information about the user and
their visit on the user's computer.
At first they were feared by the general public because it was believed they were a serious privacy risk. Nowadays nearly everyone has cookies enabled on their browser, partly because there are worse things to worry about and partly because all of the "trustworthy" websites now use cookies.
This lesson will teach you the basics of storing a cookie and retrieving a cookie, as well as explaining the various options you can set with your cookie.
At first they were feared by the general public because it was believed they were a serious privacy risk. Nowadays nearly everyone has cookies enabled on their browser, partly because there are worse things to worry about and partly because all of the "trustworthy" websites now use cookies.
This lesson will teach you the basics of storing a cookie and retrieving a cookie, as well as explaining the various options you can set with your cookie.
Creating Your First PHP Cookie
When
you create a cookie, using the function setcookie, you must specify
three arguments. These arguments are setcookie(name, value, expiration):
1. name: The name of your cookie. You will use this name to later retrieve your cookie, so don't forget it.
2. value: The value that is stored in your cookie. Common values are username(string) and last visit(date).
3. expiration: The date when the cookie will expire and be deleted. If you do not set this expiration date, then it will be treated as a session cookie and be removed when the browser is restarted.
1. name: The name of your cookie. You will use this name to later retrieve your cookie, so don't forget it.
2. value: The value that is stored in your cookie. Common values are username(string) and last visit(date).
3. expiration: The date when the cookie will expire and be deleted. If you do not set this expiration date, then it will be treated as a session cookie and be removed when the browser is restarted.
<?php
//Calculate 60 days in the future
//seconds * minutes * hours * days + current time
$inTwoMonths = 60 * 60 * 24 * 60 + time();
setcookie(lastVisit, date("G:i - m/d/y"), $inTwoMonths);
?>
//Calculate 60 days in the future
//seconds * minutes * hours * days + current time
$inTwoMonths = 60 * 60 * 24 * 60 + time();
setcookie(lastVisit, date("G:i - m/d/y"), $inTwoMonths);
?>
Retrieving Your Fresh Cookie
<?php
if(isset($_COOKIE['lastVisit']))
$visit = $_COOKIE['lastVisit'];
else
echo "You've got some stale cookies!";
echo "Your last visit was - ". $visit;
?>
if(isset($_COOKIE['lastVisit']))
$visit = $_COOKIE['lastVisit'];
else
echo "You've got some stale cookies!";
echo "Your last visit was - ". $visit;
?>
This
handy script first uses the isset function to be sure that our
"lastVisit" cookie still exists on the user's PC, if it does, then the
user's last visit is displayed. If the user visited our site on February
28, 2008 it might look something like this:
Your last visit was - 11:48 - 02/28/08
No comments:
Post a Comment