gpt4 book ai didi

PHP setcookie 添加百分号

转载 作者:行者123 更新时间:2023-11-29 09:07:50 27 4
gpt4 key购买 nike

所以,我有一个简单的脚本,允许您在任何“团队名称”之间进行选择。当您选择并提交时,它应该使用选择的值(团队名称的哈希版本)执行 php setcookie。

相关代码如下:

<?php
include 'include/db.php';

if(isset($_POST['submitteam'])) {
$team_hash = $_POST['teams'];
setcookie('ver_aet', $team_hash, time()+2592000);
header('Location: index.php');
}

$email = $_COOKIE['ver_ame'];


//Find the User Id from the Email Hash
$sql_finduid = "SELECT * FROM users_sensitive WHERE email_hash = '$email'";
$sql_finduid_result = mysql_query($sql_finduid);
while ($row = mysql_fetch_array($sql_finduid_result)) {
$user_id = $row['user_id'];
} //End Find User Id
/*
$sql_finduid = mysql_query("SELECT user_id FROM users WHERE email = '$email'");
$user_id = mysql_result($sql_finduid) or die(mysql_error());
*/

//Find the Team Id from the User Id above
$sql_findteams = "SELECT * FROM team_members WHERE user_id = '$user_id'";
$sql_findteams_result = mysql_query($sql_findteams);
if(mysql_num_rows($sql_findteams_result) < 1){
header('Location: registerteam.php?ver_ame=' . $email);
} else {

while ($row = mysql_fetch_array($sql_findteams_result)) {
$team_id = $row['team_id'];
/*
$sql_finduid = mysql_query("SELECT user_id FROM users WHERE email = '$email'");
$user_id = mysql_result($sql_finduid) or die(mysql_error());
*/



if((mysql_num_rows($sql_findteams_result)) <= 1) {

$sql_findteamname = "SELECT * FROM teams WHERE team_id = '$team_id'";
$sql_findteamname_result = mysql_query($sql_findteamname);
while ($row = mysql_fetch_array($sql_findteamname_result)) {
$team_name = $row['team_name'];
$team_hash = $row['team_name_hash'];
}

setcookie('ver_aet', $team_hash, time()+2592000);
header('Location: index.php');

} else {

//setcookie('ver_ame', $teamname_hash, time()+2592000);
//setcookie('ver_aet', $email, time()+2592000);
//header('Location: index.php'); ?>

和 HTML

Select the team you would like to view: <br />
<form method="post" action="<?PHP echo $_SERVER['PHP_SELF']; ?>">
<select name="teams">
<?PHP
$sql_findteams = "SELECT * FROM team_members WHERE user_id = '$user_id'";
$sql_findteams_result = mysql_query($sql_findteams);
while ($row = mysql_fetch_array($sql_findteams_result)) {
$team_id = $row['team_id'];
/*
$sql_finduid = mysql_query("SELECT user_id FROM users WHERE email = '$email'");
$user_id = mysql_result($sql_finduid) or die(mysql_error());
*/

$sql_findteamname = "SELECT * FROM teams WHERE team_id = '$team_id'";
$sql_findteamname_result = mysql_query($sql_findteamname);
while ($row = mysql_fetch_array($sql_findteamname_result)) {
$team_name = $row['team_name'] . "&nbsp;";
$team_hash = $row['team_name_hash'] . "<br />";
?>
<option value="<?= $team_hash; ?>"><?= $team_name . $team_hash; ?></option>
<?PHP
}
}
?>
</select>
<input type="submit" name="submitteam" value="Submit" />
</form>
</div>
</div>
</div>

基本上,“如果点击了提交按钮,则为团队名称设置cookie。如果没有点击,则继续。找到您的电子邮件的cookie,找出您属于多少个团队,如果有一个团队,将其设置为您的团队 cookie 并继续,如果没有,则显示所有可用团队并允许用户选择一个。循环”

我目前有 $team_hash 回显,只是为了表明它正在提取正确的哈希值(确实如此)。当我点击提交时,它循环到页面顶部并执行 setcookie 语句。它设置了一个 cookie,但设置后该 cookie 似乎最终会带有随机的百分号。

应该设置什么:d2fea5c982b6cb3f5bffc4998d96cbe5实际设置的是:d2fea5c982b6cb3f5bffc4998d96cbe5%3Cbr+%2F%3E

这些额外的东西从哪里来?

最佳答案

问题是您要添加 <br />当你执行 $team_hash = $row['team_name_hash'] . "<br />"; 时,在哈希的末尾当您设置选项的值时,您正在使用 $team_hash其中包含 <br /> 。当您执行 set cookie 时,<br />获取 URL 编码,因此它位于 cookie 的末尾。

简单地将行更改为:

$team_hash = $row['team_name_hash'];

关于PHP setcookie 添加百分号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6530640/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com