【问题标题】:Regarding Apache URL mapping, and PHP sessions关于 Apache URL 映射和 PHP 会话
【发布时间】:2015-02-14 21:32:13
【问题描述】:

所以这是我总结的问题:

我有这个表单,(例如在页面 X 中)将数据提交到处理页面,其地址是由 Apache 的 RewriteAlias 映射的 URL。此表单的操作 URL 有一个会话哈希键作为 GET 查询,它需要通过该查询,并且随着每个用户的每次页面加载而变化。当您在处理页面中时,该会话哈希不会更改。通常它会通过,但在这种情况下它不会。

经过一段时间的调查,我认为发生这种情况的最可能原因是,当 Apache 处理包含所有重写条件的 .htaccess 文件并更改会话哈希键时,映射的 URL 必须以某种方式重定向到页面映射页面 X。当我使用页面 X 的原始未映射 URL 时发现了这一点(它将是 index.php?snowglobe={snowglobe} 而不是 /sg/{snowglobe}。我不知道是什么导致了映射 URL 以更改会话哈希,以及如何解决此问题。

包含会话哈希的 PHP sn-p

    if(!isset($_GET['verify'])){     $_SESSION['temp_n'] =   md5(microtime(true));} //this changes at every page except the processing page

.htaccess 文件

RewriteEngine On
RewriteRule ^profile/([A-Za-z0-9]+)/?$    index.php?profile=$1        [PT]
RewriteRule ^thread/([-_A-Za-z0-9]+)/?$    index.php?thread_view=$1   [PT]
RewriteRule ^profile_nuise/([-_A-Za-z0-9]+)/?$    index.php?query=$1   [PT]
RewriteRule ^profile_nuise/([-_A-Za-z0-9]+)/notifs/?$    index.php?query=$1&notifs=all                                                    [PT]
RewriteRule ^profile_nuise/([-_A-Za-z0-9]+)/find/([A-Za-z_-]+)/?$    index.php?query=$1&find=$2                                      [PT]
RewriteRule ^profile_nuise/([-_A-Za-z0-9]+)/find/([A-Za-z_-]+)/?$    index.php?find=$2&query=$1                                     [PT]                         
RewriteRule ^profile_nuise/([-_A-Za-z0-9]+)/find/([A-Za-z_-]+)/submit    index.php?find=$2&query=$1&direct=$2_submit                                 [PT]
RewriteRule ^thread/([-_A-Za-z0-9]+)/comment/([a-z0-9]+)/?$    index.php?comment=$2&thread_view=$1                                                   [PT]
RewriteRule ^thread/([-_A-Za-z0-9]+)/comment/([a-z0-9]+)/?$    index.php?thread_view=$1&comment=$2                                               [PT]
RewriteRule ^sg/([-_A-Za-z0-9]+)/?$    index.php?snowglobe=$1      [PT]

HTML 表单

 echo "<div id='content' class='contentbox'>".$nx['31']."</div>";
echo "<form method='POST' action='".$main_dir."index.php?direct=new_post&verify=". $_SESSION['temp_n'] ."' id='post_k'>
<span id='input_save'></span>
<div class='extra_opts'><a href='add-poll' class='prompt' id='attach_poll_q'>".$nx[30]."</a></div><div id='main_new_post' class='contentbox'>"; 
echo "<div class='sect_1'><input type='text' maxlength='150' value='".$nx['17']."' class='flick largeform' name='tcha1' id='title_trigger'>
<textarea name='tcha2' class='flick largeform'>".$nx['18']."</textarea></div>";  
//post as: formats


//title and content
echo "<div class='sect_2 button_row'>

";

//check for all snowglobes they can make a thread in, of course being able to post in your own profile snowglobe is always your right, and it'll be called "1"
echo "<input type='hidden' name='sg_".$sg_details['sg_url']."' value='on'>";
//as for the rest...

echo "

<input type='submit' value='".$nx['21']."'></div>";
echo "</div></form>"; 

处理页面http://pastebin.com/iHsRbVZw

【问题讨论】:

标签: php apache .htaccess session hash


【解决方案1】:

您的问题不是很清楚,您的表单没有使用映射的重写 URL。

但是,我在 http://htaccess.madewithlove.be/ 上测试了您的重写规则,并且您通过像 http://test.com/sg/yourhashhere 这样的 url 传递的 md5 哈希可以与您的 .htaccess 文件正常工作,就像您发布它的方式一样。

也许你也可以显示你的处理页面,也许我们会在那里发现一个错误

【讨论】:

  • 一秒钟内发布。有点长:/
  • 另外,处理页面没有映射的重写 URL。会不会是个问题?
  • 此外,散列也没有出现在 /sg/ 之后,而是雪球的名称
  • 抱歉不知道,您的问题不是很清楚,需要您多方解决问题...希望我对重写规则有所帮助...
  • 1.我发送带有会话哈希的用户输入,该会话哈希在每个页面(处理页面上除外)中都发生变化,作为验证下的 GET 查询的一部分。 2. 在处理页面中,前一页的哈希与当前会话哈希匹配。 3. 会话哈希对非 url 映射页面有效,但不适用于 url 映射页面。这就是我的问题。
猜你喜欢
  • 1970-01-01
  • 2015-05-22
  • 2012-08-11
  • 1970-01-01
  • 1970-01-01
  • 2018-07-21
  • 1970-01-01
  • 2013-02-05
  • 2014-02-28
相关资源
最近更新 更多