Home / code / php

Variables

Variables in php always start with $.
Note: the name of a value can never start with a number

You can assign a value with the =


$var = 5;
$var1="text";

If you want to get variables send by a form, either by POST or GET use the following:


$var_get=$HTTP_GET_VARS["name_of_variable_in_form"];
$var_post=$HTTP_POST_VARS["name_of_variable_in_form"];

Session-variables

Session support in PHP consists of a way to preserve certain data across subsequent accesses. This enables you to build more customized applications and increase the appeal of your web site.

A visitor accessing your web site is assigned an unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL.

Example


<?php
session_start();
if (!isset($_SESSION['count']))
{
  $_SESSION['count'] = 0;
}
else
{
  $_SESSION['count']++;
}
?>

If you have a version of PHP lower then 4.0.6, you might need to use the following.


<?php
session_start();

session_register("pid");
$pid=$HTTP_SESSION_VARS['pid'];

?>

 

TOP

Latest script:

 

Books: