php怎么写网页?php写网页简单的例子

作者:澳门娱乐

index.php

登陆页面是:

 代码如下

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登陆</title>
</head>
<body>
<form name="login" action="login.php" method="post">
姓名:<input type=text name="name"><br/>
密码:<input type=password name="password"><br/>
<!-- <input type="radio" name="limits" value="1">管理员 -->
<!-- <input type="radio" name="limits" value="0">普通客户-->
<input type="submit" name="submit" value="登录">
</form>
</body>
</html>

<html>
<head>
    <title>First PHP</title>
</head>
<body>
<form name="form_a" method="post", action="fa.php">
    用户名:
    <input name="user" type="text" value="" size="12" maxlength="1000">
    <br/>
    密码:
    <input name="pwd" type="password" value="" size="12" maxlength="20">
    <br/>
    性别:
    <input name="sex" type="radio" value="男" checked>男
    <input name="sex" type="radio" value="女">女
    <br/><br/>
    购买书籍:<br/>
    <?php
        $books = array("Linux设计", "C++软件设计", "PHP网页开采");
        foreach ($books as $i=>$book) {
            echo "<input name="books" type="checkbox" value=$i>$bookn<br>n";
        }
    ?>
    <br/>

存储session的页面:

挑选课程:

<?php
header("Content-Type: text/html; charset=utf8");
if( !isset($_POST["submit"]) ){
die("错误实施");
}//检查测量试验是或不是有submit操作
 
require_once('connect.php');//链接数据库
 
if ( isset($_POST['name']) && isset($_POST['password']) ){//假若客户名和密码都不为空
 
$name = $_POST['name'];
 
$password = $_POST['password'];
 
$sql = " SELECT id, limits, message FROM user WHERE username = '$name' AND password = '$password' LIMIT 1";
 
$result = mysqli_query( $con , $sql );//推行sql 客户名和密码
 
$rows = mysqli_num_rows( $result );//再次回到顾客名密码是或不是留存
 
if( $rows != 0 ){
 
session_start();
 
while( $rows_other = mysqli_fetch_assoc($result) ){
 
$_SESSION['id'] = $rows_other['id'];
$_SESSION['name'] = $name;
$_SESSION['limits'] = $rows_other['limits'];
$_SESSION['message'] = $rows_other['message'];
 
}
 
header("refresh:0;url=welcome.php");//跳转至welcome.html页面
 
exit;
 
}else{
 
echo "客商名或密码错误";
 
echo "<script>
alert('客商名或密码错误');
setTimeout(function(){window.location.href='login.html';},1000);
</script>";
 
}
 
}else{
 
echo "表单填写不完整";
 
echo "<script>
alert('表单填写不完整');
setTimeout(function(){window.location.href='login.html';},1000);
</script>";
 
}
?>

 代码如下

登录后跳转的页面,遵照分裂的客户体现分歧的权位和客户名:

   <select name="class" id="class">
    <?php
        $classes = array("C++程序设计", "C程序设计", "MFC程序设计", "Qt编制程序", "互连网编制程序", "SQL数据库设计");
        foreach ($classes as $key=>$value) {
            echo '<option value="' .$key.'">' . $value . '</option>n';
        }
    ?>
    </select>
    <br/>
    <input name="submit" type="submit" value="提交">
</form>
</body>

<?php
 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
 
<?php
 
session_start();
 
if( isset($_SESSION['id']) ){
 
require_once('connect.php');
 
$id = $_SESSION['id'];
$name = $_SESSION['name'];
$limits = $_SESSION['limits'];
$message = $_SESSION['message'];
 
if( $limits == 1 ){
 
echo 'hello, 管理员' . '<br/>';
 
}else{
 
echo 'helo, 普通顾客' . '<br/>';
}
 
echo 'hello you name is:' . $name;
 
}else{
 
echo '未登录!';
 
header("refresh:3;url=login.html");
 
}
?>
 
 
</body>
</html>
?>

</html>

运用session注意事项

fa.php

1.在现阶段页面要选取session时我们在文件最前边未有输入内容时抬高session_start();

 代码如下

2.session有二个时光范围的那一个我们得以张开修改的,具体如下

<?php
    #echo 'user: ' . $_POST["user"];
    print_r($_POST);
?>

 其实PHP5 Session还提供了叁个函数 session_set_cookie_params(); 来设置PHP5 Session的生存期的,该函数必需在 session_start() 函数调用此前调用:

<?php
    // 保存一天
    $lifeTime = 24 * 3600;
    session_set_cookie_params($lifeTime);
    session_start();
?>

本文由澳门娱乐6165发布,转载请注明来源

关键词: