<?php
session_start();include 'common.php';
if($_SERVER['REQUEST_METHOD']==='POST'){
$u=trim($_POST['username']);$p=trim($_POST['password']);$p2=trim($_POST['password2']);
if($p!==$p2){$e="密码不一致";}elseif(!$u||!$p){$e="用户名密码不能为空";}else{
$f='user/'.APPID1.suffix;$us=[];if(file_exists($f))$us=json_decode(file_get_contents($f),true);
if(isset($us[$u])){$e="用户名已存在";}else{$us[$u]=password_hash($p,PASSWORD_BCRYPT);
file_put_contents($f,json_encode($us,JSON_UNESCAPED_UNICODE));$_SESSION['user']=$u;
header('Location:index.php');exit;}}}?><!DOCTYPE html><html lang="zh-CN"><head><meta charset="utf-8"><title>注册</title><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><style>body{background:#fff;font-family:"PingFang SC","Helvetica Neue",Helvetica,Arial,"Microsoft YaHei",sans-serif;margin:0}.login-wrap{max-width:900px;margin:60px auto 0 auto;padding:0 16px}.login-form{margin:0 auto;max-width:1200px}.login-input{width:100%;box-sizing:border-box;font-size:18px;padding:10px 12px;border:1px solid #d3d6db;border-radius:5px;margin-bottom:23px;outline:none;transition:border 0.2s;background:#fafbfc}.login-input:focus{border-color:#6a7ba2;background:#fff}.login-btn{display:block;width:100%;background:#393f45;color:#fff;border:none;border-radius:6px;padding:13px 0;font-size:22px;font-weight:500;letter-spacing:8px;cursor:pointer;text-align:center;margin-top:12px;transition:background 0.17s}.login-btn:hover{background:#23272c}.login-error{color:#e74c3c;background:#fff4f2;border:1px solid #f3b5b2;padding:10px 13px;border-radius:6px;margin-bottom:20px;font-size:0.96em;text-align:center}.login-links{margin-top:22px;text-align:center}.login-links a{color:#393f45;text-decoration:underline;font-size:16px;margin:0 7px;transition:color 0.18s}.login-links a:hover{color:#6a7ba2}@media (max-width:600px){.login-wrap{margin:24px 0 0 0}.login-btn{font-size:18px;letter-spacing:3px}.login-input{font-size:16px}}</style></head><body><div class="login-wrap"><form class="login-form" method="post" autocomplete="off"><?php if(!empty($e))echo "<div class='login-error'>$e</div>";?><input class="login-input" type="text" name="username" placeholder="手机号/用户名" required autocomplete="username" value="<?=htmlspecialchars($_POST['username']??'')?>"><input class="login-input" type="password" name="password" placeholder="密码" required autocomplete="new-password"><input class="login-input" type="password" name="password2" placeholder="再次输入密码" required autocomplete="new-password"><button class="login-btn" type="submit">注册</button></form><div class="login-links">已有账号？<a href="login.php">去登录</a></div></div></body></html><?php include'footer.php';?>
