[PHP] 跳转以及回到原来的地址

回到原来的地址:

1.PHP(PHP代码)

Header('Location:'.$_SERVER["HTTP_REFERER"]);

 

2.JavaScript(相当于后退按钮,-1代表后退一步)(HTML代码)

<a href="javascript:history.back(-1)">Back</a>

 

跳转地址:

1.Header函数 (PHP代码)

header("Location: http://www.google.com");

 

2.JavaScript (JavaScript代码)

window.location.href=‘www.baidu.com’
location.replace("www.baidu.com")

 

3.HTML超链接(HTML代码)

<a href="www.google.com">Google</a>

 

4.HTML中META头内容(其中5表示5秒后跳转)(HTML代码)

<meta http-equiv="refresh" content="5" url=http://www.baidu.com/"> 

 

转载于:https://www.cnblogs.com/Liangw/p/3165143.html

好的,这是一个比较复杂的问题,需要分几个步骤来完成。 1. 编写登录页面 可以使用 HTML 和 CSS 来编写登录页面,其中包括一个表单,表单中包含一个输入框和一个密码框,以及一个登录按钮。 2. 前端校验 使用 JavaScript 对用户输入的信息进行校验。对于 userID,可以使用正则表达式判断是否包含字母;对于 password,判断其长度是否为 6。 3. 与数据库比较 使用后端技术(如 PHP 或 Node.js)将用户输入的信息与数据库中的数据进行比较。如果存在该用户,则取出该用户的所有数据,将其展示到表格中;否则,弹出登录失败的提示框,跳转原来的登录页面。 下面是一个简单的示例代码,仅供参考: HTML 代码: ```html <!DOCTYPE html> <html> <head> <title>Login Page</title> <style type="text/css"> #login-form { margin: 50px auto; width: 300px; border: 1px solid #ccc; padding: 20px; } input[type="text"], input[type="password"] { margin-bottom: 10px; } input[type="submit"] { background-color: #4CAF50; color: white; padding: 10px; border: none; border-radius: 5px; cursor: pointer; } </style> </head> <body> <div id="login-form"> <h2>Login</h2> <form id="login" method="post"> <label for="userID">User ID:</label><br> <input type="text" id="userID" name="userID"><br> <label for="password">Password:</label><br> <input type="password" id="password" name="password"><br> <input type="submit" value="Login"> </form> </div> <script type="text/javascript" src="login.js"></script> </body> </html> ``` JavaScript 代码: ```js // 获取表单和输入框 var loginForm = document.getElementById('login'); var userIDInput = document.getElementById('userID'); var passwordInput = document.getElementById('password'); // 给表单添加提交事件 loginForm.addEventListener('submit', function(event) { // 阻止表单默认的提交行为 event.preventDefault(); // 获取用户输入的信息 var userID = userIDInput.value; var password = passwordInput.value; // 前端校验 if (!/^[0-9]+$/.test(userID)) { alert('User ID should only contain numbers!'); return; } if (password.length !== 6) { alert('Password should be 6 characters long!'); return; } // 向后端发送请求,比较用户信息 var xhr = new XMLHttpRequest(); xhr.open('POST', 'check_login.php'); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { // 比较成功,将用户数据展示到表格中 var userData = JSON.parse(xhr.responseText); // TODO: 将 userData 展示到表格中 } else if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 401) { // 比较失败,弹出提示框 alert('Login failed!'); } }; xhr.send('userID=' + userID + '&password=' + password); }); ``` PHP 代码(check_login.php): ```php <?php // 获取用户输入的信息 $userID = $_POST['userID']; $password = $_POST['password']; // 与数据库比较 // TODO: 在这里写查询数据库的代码,如果存在该用户,则将其数据返回 if (/* 比较成功 */) { header('Content-Type: application/json'); echo json_encode(/* 用户数据 */); } else { header('HTTP/1.1 401 Unauthorized'); } ``` 注意,上述代码仅为示例,实际情况中需要根据具体需求进行修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值