$_SERVER---An array of server environment variables contains information such as headers, file paths, and script locations.
Ex:
header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . "mypage.php?msg=1");
$WEB_HOST = "https://" . $_SERVER['HTTP_HOST'];
header("Location: " . $WEB_HOST . dirname($_SERVER['PHP_SELF']) . "/" . "mypage.php?msg=1");
$_GET---An array of variables passed to the script via the GET method
$_POST---An array of variables passed to the script via the POST method
$_COOKIE---An array of cookie variables
$_ENV---An array of the server environment variables
$_REQUEST---An array of all user input including the contents of input including $_GET, $_POST, and $_COOKIE
$_SESSION---An array of currently registered session variables
------------- initial -------------
session_start();
/* When this script is run for the first time from a browser, a session ID is generated by session_start(). session_start() attempts to set a cookie when initiating a session for the first time. If the page is reloaded, the same session ID is allocated to the user. This action assumes that the user has cookies enabled. You must call this function before output anything to the browser. If 'session.cookie_lifetime' is not set in php.ini, the cookie is no longer stored when the user restart the browser. It's not sure that the client's browser will accept cookies. The safe way is to use SID (PHP makes a name/value pair for a session ID)
Ex. <a href="apage.html?<?php echo SID; ?>"> Go Here</a>
// to set or get a session id
session_id();
//return the current dir to which session files are saved or set the dir.
session_save_path([path]);
Ex.
if(!session_id()){
session_start();
}
$_SESSION['loginname'] = $_POST['loginname'];
------------- destroy -------------
$_SESSION=array();
session_destroy();
****** It seems that $varname and $_SESSION['varname'] use the same memory address.
When modify $varname, $_SESSION['varname'] changes at the same time.
$_FILES---An array of variables related to file uploads
$_FILES['fileupload']['name']: Original name of uploaded file
$_FILES['fileupload']['tmp_name'] Path to temporary file
$_FILES['fileupload']['size'] Size of uploaded file(in bytes)
$_FILES['fileupload']['type'] MIME type of uploaded file (where given by client) -> [image/gif]
Ex.
// HTML forms that include file upload fields must include an ENCTYPE argument:
<p>
<form action="dfa" enctype="multipart/form-data" method="post">
<!-- max file size: 50K, must be 'MAX_FILE_SIZE' for PHP to work with -->
<input type='hidden' name='MAX_FILE_SIZE' value='51200' />
<p> File to Upload: <input type="file" name="fileupload" id="name"> </p>
</form>
</p>
// Accept file
<?php
$file_dir = "/path/to/upload/dir";
foreach($_FILES as $file_name => $file_array)
{
echo "path: $file_array['tmp_name'] < br /> /n";
echo "name: $file_array['name'] < br /> /n";
echo "type: $file_array['type'] < br /> /n";
echo "size: $file_array['size'] < br /> /n";
}
if (is_uploaded_file($file_array['tmp_name']))
{
move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array['name']") or die("Couldn't copy");
echo "file was moved";
}
?>
No comments:
Post a Comment