Posted by forcescript on February 26, 2009
When you are working with an application, you open it, do some changes and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are and what you do because the HTTP address doesn’t maintain state.
A PHP session solves this problem by allowing you to store user information on the server for later use (i.e. username, shopping items, etc). However, session information is temporary and will be deleted after the user has left the website. If you need a permanent storage you may want to store the data in a database.
Sessions work by creating a unique id (UID) for each visitor and store variables based on this UID. The UID is either stored in a cookie or is propagated in the URL.
Starting a PHP Session
Before you can store user information in your PHP session, you must first start up the session.
Note: The session_start() function must appear BEFORE the <html> tag:
<?php session_start(); ?>
<html>
<body>
</body>
</html>
The code above will register the user’s session with the server, allow you to start saving user information, and assign a UID for that user’s session.
Storing a Session Variable
The correct way to store and retrieve session variables is to use the PHP $_SESSION variable:
<?php
session_start();
// store session data
$_SESSION['views']=1;
?>
<html>
<body>
<?php
//retrieve session data
echo “Pageviews=”. $_SESSION['views'];
?>
</body>
</html>
Output:
Pageviews=1
Destroying a Session
If you wish to delete some session data, you can use the unset() or the session_destroy() function.
The unset() function is used to free the specified session variable:
<?php
unset($_SESSION['views']);
?>
or
<?php
session_destroy();
?>
Note: session_destroy() will reset your session and you will lose all your stored session data.
Posted by forcescript on February 25, 2009
What is a Cookie?
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user’s computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.
How to Create a Cookie?
The setcookie() function is used to set a cookie.
Note: The setcookie() function must appear BEFORE the <html> tag.
setcookie(name, value, expire, path, domain);
Example
In the example below, we will create a cookie named “user” and assign the value “Alex Porter” to it. We also specify that the cookie should expire after one hour:
<?php
setcookie(“user”, “Alex Porter”, time()+3600);
?>
<html>
<body>
</body>
</html>
How to Retrieve a Cookie Value?
The PHP $_COOKIE variable is used to retrieve a cookie value.
In the example below, we retrieve the value of the cookie named “user” and display it on a page:
<?php
// Print a cookie
echo $_COOKIE["user"];
// A way to view all cookies
print_r($_COOKIE);
?>
In the following example we use the isset() function to find out if a cookie has been set:
<html>
<body>
<?php
if (isset($_COOKIE["user"]))
echo “Welcome ” . $_COOKIE["user"] . “!<br />”;
else
echo “Welcome guest!<br />”;
?>
</body>
</html>
How to Delete a Cookie?
When deleting a cookie you should assure that the expiration date is in the past.
Delete example:
<?php
// set the expiration date to one hour ago
setcookie(“user”, “”, time()-3600);
?>
Posted by forcescript on February 25, 2009
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web host can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation.
Web Hosting Choice is a free research guide to help users choose the right web host for their personal or business site. Our focus is on providing a simple, easy to follow web site to help users choose the best web hosting plan most suitable for a small site or for a large e-commerce web site.
You can find more web hosting plan at web hosting choice. You can compare one hosting with others, it’s price, disk space, added domain, Data Transfer, and more.
Posted by forcescript on February 24, 2009
“Do over’s” are fun if you are playing a game. They are not fun when designing Access Database Forms and Reports. We will show you an easy way to save time every time you create a new Form or Report.
Posted by forcescript on February 23, 2009
You can save a great deal of time, code, and database bloat by using simple custom functions. We will show you a very easy way to open your forms using a simple Custom Function.
Posted by forcescript on February 22, 2009
Too many open forms clutter up the screen and waste memory. You can avoid this by using a simple Custom Function that gives you the option to close the current Form when you open another. We will show you how to use this method in your Access Database.
Posted by forcescript on February 21, 2009
Spyware got you down? Don’t hesitate, take action and eliminate those pests from your computer now! I will show you the way.
Posted by forcescript on February 20, 2009
If your browser’s homepage has been mysteriously pointing to coolwebsearch then be very careful. Despite the title I promise you there is nothing “cool” about it.
Posted by forcescript on February 19, 2009
Like a lot of people, you may be contemplating whether or not to download a PC Satellite TV software to your computer. Your decision could be based upon a need to economize everything you do because of a plummeting economy, or the idea of having access to a wide variety of free Worldwide TV entertainment on your PC just seems too good to pass up. The question is will any Satellite TV software once installed on a PC replace home TV.
Posted by forcescript on February 18, 2009
If watching traditional TV isn’t good enough or when there’s a need to supplement it, a TV player that provides access to Internet TV offers another dimension. But choosing the right player or gateway is essential to ones ability and affordability while meeting the task at hand. To enhance more TV enjoyment means finding a gateway that can access 1000s of exciting live and recoded TV/radio channels Worldwide and more.