将cookie值分配到文本框中

编程入门 行业动态 更新时间:2024-10-23 19:26:32
本文介绍了将cookie值分配到文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在下面有这个代码我试图找不到会话和cookie的东西。我想知道如何在注销后根据cookie值填写用户名和密码字段 我的尝试:

I have this code below I am trying to undestand session and cookie things.I am wondering How to fill username and password fields based on cookie value after log out What I have tried:

<?php session_start(); ob_start(); if (isset($_COOKIE['name']) and isset($_COOKIE['pass'])) { $c_name = $_COOKIE['name']; $c_pass = $_COOKIE['pass']; echo "<script> document.getElementById('u_name2).val='$c_name'; </script>"; } ?> <?php if (isset($_SESSION['login'])) { header('location:welcome.php'); } else { if (isset($_POST['submit'])) { $name = $_POST['username']; $pass = $_POST['password']; $db = new PDO('mysql:host=localhost;dbname=testing;charset=utf8', 'root', ''); $query = $db->prepare('select * from users where username=? and password=?'); $query->execute([$name, $pass]); $count = $query->rowCount(); if ($query->rowCount()) { $_SESSION['login'] = true; $_SESSION['username'] = $name; if (isset($_POST['remember'])) { setcookie('name', $name, time() + 60 * 60 * 6); setcookie('pass', $pass, time() + 60 * 60 * 6); } header('location:welcome.php'); } } else { ?> <form action="" method="post"> UserName <input type="text" name="username" id="u_name"><br> Password : <input type="text" name="password" id="u_pass"><br> Remember Me :<input type="checkbox" name="remember" > <br> <input type="submit" name="submit"><br> </form> <?php } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> </body> </html> <?php

推荐答案

_COOKIE ['name'])和isset( _COOKIE['name']) and isset(

_COOKIE ['pass'])){ _COOKIE['pass'])) {

c_name =

更多推荐

将cookie值分配到文本框中

本文发布于:2023-11-30 01:19:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648239.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:框中   分配   文本   cookie

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!