Home Superglobals

Суперглобальный массив $ _SESSION

session_start - Initializes the session by the beginning.

1
2
3
4
5
6
7
8
session_start(); 
if (!isset($_SESSION['counter'])) {
 $_SESSION['counter']=0;
}
echo "Вы обновили эту страницу ".$_SESSION['counter']++." раз. ";
if ($_SESSION['counter']==10){ 
 session_destroy();
}

session_destroy - Destruction of session by.

session_unregister

1
session_unregister('passwd');

session_unset() - Nichtozhaem all global variables session.

1
2
3
4
5
6
7
8
9
10
11
session_start(); 
print_r($ _SESSION);   / / Display all session variables
if (!($ _SESSION['Login']=="Pit" & & $ _SESSION['Passwd']==123)) ?>
 
Secret info... / / Here is 
    / / Secret information:)
 
session_start();
session_unregister('Passwd');  / / Destroy the password
unset($ _SESSION['Login']);    / / Destroy the login
print_r($ _SESSION);    / / Output global variables session

Superglobal $ _SERVER

$ _SERVER ['DOCUMENT_ROOT'] - This element contains the path to the root directory of the server.

1
echo $ _SERVER['DOCUMENT_ROOT']; / / Outputs eg K: / home/p4/www

$ _SERVER ['HTTP_HOST'] - This element contains the name of the server.

1
echo $ _SERVER['HTTP_HOST']; / / Will p4 

$ _SERVER ['HTTP_REFERER'] - This element contains the page address from which the visitor arrived at this page.

$ _SERVER ['HTTP_USER_AGENT'] - Displays the current version.

$ _SERVER ['REMOTE_ADDR'] - Displays the IP-address of the client.

$ _SERVER ['SCRIPT_FILENAME'] - Put the absolute path from the root disk.

1
// к примеру K:/home/p4/www/index.php

$ _SERVER ['SERVER_NAME'] - Put the name of the server, usually coinciding with the domain name site located on it.

1
// выведет http://p4 

$ _SERVER ['REQUEST_METHOD'] - Placed a request method that is used to call the script: GET or POST.

$ _SERVER ['QUERY_STRING'] - Entered the parameters passed to the script if the query string is the address.

1
2
3
//строка
http://www.mysite.ru/test/index.php?id=1&test=wet&id_theme=512
//выведет id=1&test=wet&id_theme=512 

$ _SERVER ['PHP_SELF']

$ _SERVER ['REQUEST_URI'] - Contains the name of the script from the root directory of the virtual host and options.

1
2
http://www.mysite.ru/test/index.php?id=1&test=wet&id_theme=512
// выдаст /test/index.php?id=1&test=wet&id_theme=512" 

Superglobal $ _FILES

$ _FILES

Upload files to the server by using multipartForm, which has a file upload field. The parameter indicates the value of enctype multipart / form-data:

1 $ _FILES ['Uploadfile'] ['name'] - The name of the file before sending it to the server, for example, pict.gif;
$ _FILES ['Uploadfile'] ['size'] - The size of a received file in bytes;
$ _FILES ['Uploadfile'] ['type'] - MIME-type of a received file (if the browser is able to define it), for example: Image / gif, image / png, image / jpeg, text / html;
$ _FILES ['Uploadfile'] ['tmp_name'] (As we called file upload field) - contains the name of the file in a temporary directory, for example: / Tmp/phpV3b3qY;
$ _FILES ['Uploadfile'] ['error'] - The error code that may occur when loading the file.
1
2
3
4
5
6
7
8
9
10
11
12
13
$ Archive_dir=". / Docs / mark /";
$ Userfile_name = $ _FILES['Userfile']['Name'];
$ Userfile_tmp_name = $ _FILES['Userfile']['Tmp_name'];
$ Userfile_size = $ _FILES['Userfile']['Size'];
$ Userfile_type = $ _FILES['Userfile']['Type'];
$ Uniq = substr( md5(uniqid (rand())), 0, 10 );  
$ Filename = basename($ Userfile_name);
$ Filename=$ Uniq.$ Filename;  
@move_uploaded_file($ Userfile_tmp_name,"$ Archive_dir/$ Filename");      
@isset($ _ENV['WINDIR']) & & !@unlink($ Userfile);
$ Foto=". / Docs / mark /".$ Filename;
$ Archive_dir=". / Docs / mark /".$ Filename;
img_resize($ Foto, $ Archive_dir, 91, 58);

Superglobal $ _COOKIE

Sending a cookie function setcookie ()

1
2
setcookie ("TestCookie", $value);
setcookie ("TestCookie", $value,time()+3600);  /* период действия - 1 час */

setcookie ()

1
setcookie ("TestCookie", "", time() - 3600);

Calling cookies

1
echo $ _COOKIE[TestCookie];

Through all the cookies.

1
2
3
4
5
6
7
8
9
setcookie("Cookie [three]", "Cookiethree");
setcookie("Cookie [two]", "Cookietwo");
setcookie("Cookie [one]", "Cookieone");
if (isset($ _COOKIE['Cookie'])) {
  foreach ($ _COOKIE['Cookie'] as $ Name => $ Value) {
    echo "$ Name : $ Value 
";
  }
}

Superglobal $ _REQUEST

$ _REQUEST - Gives access to all the variables $ _GET, $ _POST and $ _COOKIE.

1
$_REQUEST['name'];

Nice Ajax Poll

Which one of my extensions is the best?

Statistics

Advertisement