关于Apache URL映射和PHP会话


Regarding Apache URL mapping, and PHP sessions

所以我的问题总结如下:

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

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

包含会话哈希的PHP代码段

    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

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

然而,我在上测试了你的重写规则http://htaccess.madewithlove.be/通过http://test.com/sg/yourhashhere这样的url传递的md5哈希可以很好地处理.htaccess文件,就像你发布它的方式一样

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