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

strip query string after page load

本文关键字:查询 字符串 剥离 加载      更新时间:2023-09-26

im正在开发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['errors'] = "Delete Failed: For Some Reason";

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

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