A fundamental characteristic of Web is:

  • The stateless interaction between browsers and web servers
  • Each HTTP request sent to a web server is independent of any other request.

Applications that require complex user interaction can’t be implemented as a series of unrelated, stateless web pages. An often-cited example is a shopping cart in which items are added to the cart while searching or browsing an on-line store. The state of the shopping cart (the selected items) needs to be stored somewhere to be displayed when the user visits the order page.

There are three ways to build an application that keeps state:

  • Variables can be passed between scripts as query string appended with the URL.
  • Variables can be stored in the browser at client-side as cookies and then can be included with each request.
  • Variables can be stored on the server as session variables

Passing Variables Between Scripts

The simplest way is to add the variables to the url:

www.seecs.edu.pk/myscript.php?variable=value

You can chain these variables using an ampersand.

myscript.php?variable1=value1&variable2=value2&…

As per normal you can access these variables easily. You just need to use $_GET array, and access variables through their names. E.g

$var1 = $_GET[“variable1″];

URL Encoding

However this can lead to problems as you can’t have certain characters in url’s – spaces for example, more ampersands, colons and so on. To deal with this php has the urlencode() function.This converts all those problem characters into their url friendly counterparts. E.g.

<?
$str = urlencode("script.php?name=T. J.&lastname=O’Reilly");
print "<A HREF=$str>link</A>";
?>

You’ll get a hyperlink something like given below:

<A HREF=script.php%3Fname%3DT.+J.%26lastname%3DO%27Reilly>link</A>

Nobody can now manipulate your link.

Next >> Lecture 7. Cookies in PHP

Tagged with: PHP
 

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

Looking for something?

Use the form below to search the site:


Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Related News Feeds

Set your Twitter account name in your settings to use the TwitterBar Section.