PHP Web

PHP Web

§EGPCS Variables

$HTTP_ENV_VARS
$_ENV
 
$HTT_GET_VARS
$_GET
 
$HTTP_POST_VARS
$_POST
 
$HTTP_POST_FILES
$_FILES
 
$HTTP_COOKIE_VARS
$_COOKIE
 
$HTTP_SERVER_VARS
$_SERVER
 
$_REQUEST 
//when register_globals is on
$_GET + $_POST + $_COOKIE
 
$PHP_SELF

§Processinq Forms
•Autoquotinq parameters
-set magic_quotes_qpc to true

$value=init_get('magic_quotes_gpc') ? 
stripslashes($_GET['param']) : $_GET['param'];

•Self processing

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" 
  method="POST">

•Multivalued parameters

<select name="language[]">

•File upload
-file limits
hard limit: upload_max_filesize
soft limit:

<input type="hidden" name="MAX_FILE_SIZE" value="10240">

-form

<form enctype="multipart/form-data" action="<?= PHP_SELF ?>" 
  method="POST">

-Process

if (is_uploaded_file( $_FILES['toProcess']['tmp_name']) {
	//success
}

•Redirection

<?php
header('location: http://url/f.html');
exit();
?>
or:
<?php
echo "<script>document.location.href='news.php'</script>";
?>

•Authentication

$_SERVER['PHP_AUTH_USER'];
$_SERVER['PHP_AUTH_PW'];

•Cookie

<?php
$page_accesses=$_COOKIE['access'];
setcookie('accesses', ++$page_accesses);
?>

•Sessions

See PHP Manual

<?php
 
Use auto start
-In php.ini set
session.auto_start = 1
 
Otherwise use
session_start(); 
// This has to be the first line of the page
// Unless you store object in the session 
// in which case, you need to include the class first.
 
if (empty($_SESSION['count'])) {
 $_SESSION['count'] = 1;
} else {
 $_SESSION['count']++;
}
?>
This entry was posted in php. Bookmark the permalink.