[第11堂] 課程範例

login1.php

<html>
<form action="login2.php" method="post" name="form1″><br>
Input your data:<br>
<input name="name" type="text" value=""><br>
<input name="pwd" type="text" value=""><br>
<input name="email" type="text" value=""><br>
<input name="submit" type="submit" value="GO"><br>
</form>
</html>

——————————-

login2.php

<?php
session_start();
$_SESSION[“name"]=$_POST[“name"];
$_SESSION[“pwd"]=$_POST[“pwd"];
$_SESSION[“email"]=$_POST[“email"];
echo “name:".$_SESSION[“name"]."<br>";
echo “pwd:".$_SESSION[“pwd"]."<br>";
echo “email:".$_SESSION[“email"]."<br>";
?>

————————-

WebForm1.aspx

protected void Button1_Click(object sender, EventArgs e)
{
Session.Add(“name", TextBox1.Text);
Session.Add(“pwd", TextBox2.Text);
Session.Add(“email", TextBox3.Text);

//重新導向新的頁面
Response.Redirect(“WebForm2.aspx");
}

————————

WebForm2.aspx

//於page_load執行下列程式碼

if (Session[“name"] != null)
{
Response.Write(“name:" + Session[“name"].ToString()+"<br>");
Response.Write(“pwd:" + Session[“pwd"].ToString() + “<br>");
Response.Write(“email:" + Session[“email"].ToString() + “<br>");
}
else
{
Response.Write(“no session data");
}

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *