Artificial Intelligence Programming Lab(AIPLab) 討論區

102學年(下)課程2014Spring => 102(下)程式設計(二) => 主題作者是: admin 於 五月 25, 2015, 05:07:19 pm



主題: [資訊] PHP 基本語法
作者: admin五月 25, 2015, 05:07:19 pm
程式碼: [Select]
PHP 基本語法
<?php
echo "$Var1, $Var2”;
print "
Name=.$Var1.“No=.$Var2;
?>

[hr]
PHP 輸入表單參數
$userName=$_POST["Usename"];
$userPwd=$_POST["Password"];
$userName=$_REQUEST["Usename"];
$userPwd=$_REQUEST["Password"];
PHP SESSION
session_start();
$_SESSION['auth'] = true;
$Auth = $_SESSION['auth'];
unset($_SESSION['auth']);
[hr]
PHP判斷式和跳頁
if(isset($_POST["Submit"])){
if ($userName == "1111" && $userPwd =="1234")
{
    $redir = "ex2-main.php";
header("Location: $redir");
exit;
}
else
{
$AuthMessage="Incorrect username/password";
}
}
[hr]
PHP陣列
$D = array();
$D = array(
    "foo" => "bar",
    "bar" => "foo",
);
$D["foo"]="zzz";
$X=$D["bar"];
PHP日期
$dateStr = date("Y/m/d");
$dateStr2= date('Y/m/d', strtotime($dateStr. ' - 1 days'));