gpt4 book ai didi

php - 页面加载后剥离查询字符串

转载 作者:行者123 更新时间:2023-11-30 17:59:28 25 4
gpt4 key购买 nike

我正在开发 php,我的网页 url 是这样的

http://localhost/myweb/?action=news
http://localhost/myweb/?action=my_profile
http://localhost/myweb/?action=my_upload
http://localhost/myweb/?action=my_collection
http://localhost/myweb/?action=chat
http://localhost/myweb/?action=my_friends
etc

例如,在特定页面中有访问 href 链接的删除功能

http://localhost/myweb/?action=my_friends&delete=2414535435 <-friends id

我这样做是为了让链接在不查看源代码的情况下变得整洁

a href='#'

并使用javascript访问真实链接

$('.deleteclass').on('click', function () {
var name= $(this).attr('nameattr');
if(confirm('You sure want to delete '+name+'?')){
window.location='?action=my_friends&delete='+this.id;
}
});

问题是,在我处理删除和加载页面后,我不想要地址栏上的完整链接。

http://localhost/myweb/?action=my_friends&delete=2414535435

我需要让它在地址栏上看起来像这样

http://localhost/myweb/?action=my_friends

这可能吗?也许通过 mod 重写?

最佳答案

您不能在浏览器加载页面后删除 url。

只需在删除或其他操作后进行重定向即可。

header('Location: /myweb/?action=my_friends');

将错误/成功消息添加到 session 变量(在执行 header 之前的操作脚本中),以便您可以在其他页面上显示它们

$_SESSION['errors'] = "Delete Failed: For Some Reason";

并且在其他页面上检查 session 变量是否存在,显示它然后删除它(否则它会留在那里并且页面将继续认为有错误)

<?php

if(isset($_SESSION['errors'])) {
//Do some code to show the error
...
unset($_SESSION['errors']); //delete the error messages
}

关于php - 页面加载后剥离查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17389467/

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