【问题标题】:How to hide query strings from url in php?如何在php中隐藏来自url的查询字符串?
【发布时间】:2013-03-24 08:17:05
【问题描述】:

我正在尝试制作一个消息系统,当接收者正在阅读消息时,会有一个链接来回复消息,如下所示:

<a href=mail.php?action=compose&toid='".urlencode($viewrow['sender'])."'&subject='RE:+".urlencode($viewrow['subject'])."'&message=".urlencode($viewrow['message']).">Reply</a>

正在从 mysql 中检索发件人、主题和消息。

用户看到的是这样的:

http://www.somesite.com/author/mail.php?action=compose&toid='8'&subject='RE:+test+subject'&message=test+message

我需要知道的是,是否有办法隐藏回复 url 中的主题和消息,所以用户只会在地址栏上看到:

http://www.somesite.com/author/mail.php?action=compose&toid='8'

这是从 db 中检索主题、消息和 ID 的方式。

//view message
if (isset($_GET['action']) && $_GET['action'] == inbox) { 
        if(isset($_GET['viewid'])) { 
            $viewid = $_GET['viewid'];
    /*      $viewsql = "select * from mail where reciever='".$userid."' and mail_id=".$viewid; */
            $viewsql = "select * from mail, authors where (mail.sender = authors.id) and (mail.reciever = '".$userid."') and (mail.reciever_deleted ='0') and mail.mail_id = ".$viewid;
            $viewquery = mysql_query($viewsql,$connection) or die(mysql_error());
            $viewrow = mysql_fetch_assoc($viewquery);
            if ($viewrow['reciever'] == $userid) { //check if user is the reciever
            } else { 
                header('Location: mail.php?action=inbox');
                exit; 
            } 
            echo "<h3>Lendo mensagem particular da Caixa de Entrada</h3>";
            echo "<table align=\"center\" width=\"75%\" class=\"sortable\">
                    <tr>
                        <td colspan='2' style=\"text-align:center;font-weight:normal;\">Mensagem particular enviada por ".$viewrow['displayname']." em ".date('d/m/y',strtotime($viewrow['created_at'])).".</td>
                    </tr>
                    <tr>
                        <td colspan='2'>
                            <img style=\"float:left;padding: 5px 15px 5px 2px;width: 65px;\" src=\"".$viewrow['gravatar']."\" alt=\"".$viewrow['displayname']."\" title=\"".$viewrow['displayname']."\" />
                            <div style=\"padding: 8px 5px 2px;\"><span style=\"font-size:1.6em;\">&#8594; </span><b>".$viewrow['subject']."</b></div>
                            <div style=\"padding: 8px 30px 8px 85px;\">".nl2br($viewrow['message'])."<br /></div>
                            <span style=\"float:right;\">
                                <a href=mail.php?action=compose&toid='".urlencode($viewrow['sender'])."'&subject='RE:+".urlencode($viewrow['subject'])."'&message=".urlencode($viewrow['message']).">Responder</a> | <a href=javascript:confirmDelete('mail.php?action=inbox&deleteid=".$viewid."')>Apagar</a>
                            </span>
                        </td>
                    </tr>
                </table>";

            // mark as read by reciever
            $query="update mail set mail_status='read' where reciever = '$userid' and mail_id = '$viewid'"; 
            mysql_query($query,$connection) or die(mysql_error());
        }                   
    }elseif (isset($_GET['action']) && $_GET['action'] == outbox) { ...

我知道我需要使用 post,但是如何使用?

我试过了,但还是不行。

对不起我的愚蠢..

【问题讨论】:

  • 使用POST 而不是GET
  • 如果你有ID,应该可以得到帖子的主题和内容吧?请务必从 url 中删除单引号。
  • 我尝试使用 POST 但没有成功,也许我的检索不正确。我不知道,我是新手...
  • @DannyBeckett GET/POST 没有问题,因为显示的代码是获取和显示消息的代码,而问题与提供的回复脚本链接有关。
  • 将回复链接替换为具有提交按钮和隐藏字段的表单,以获取现在包含在 URL 中的信息

标签: php url query-string


【解决方案1】:

您不能使用 POST 通过&lt;a&gt; 将信息发送到页面。
但是您可以使用 JavaScript 或表单来完成。

【讨论】:

    【解决方案2】:

    您无法隐藏查询字符串,但可以改为通过 POST 发送数据,这在地址栏中不可见。为此,您需要使用表格提交数据;虽然 Pietroalbini 是正确的,您不能使用 a 元素,但您可以设置 button 的样式,使其看起来与微不足道的相同:

    <style>
    button {
        background:none;
        border: 0;
        border-bottom:1px solid blue;
        color: blue;
        padding:0;        
    }
    </style>
    
    <form action="script.php" method="post">
         <input type="text" name="Test"/>
         <button type="submit">Submit</button>
    </form>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-23
      • 2013-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-26
      • 2018-09-01
      相关资源
      最近更新 更多