gpt4 book ai didi

php - 更改我的 .htaccess 文件后,我的 php 上的 POST 方法不再起作用

转载 作者:行者123 更新时间:2023-12-03 09:22:46 24 4
gpt4 key购买 nike

我最近做了一些研究,以了解如何修改我的 .htaccess 文件以隐藏 URL 中的 .php 扩展名。我使用以下代码让它按照我想要的方式工作:

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.guitrum.com/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.guitrum.com/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

ErrorDocument 404 /404.php

DirectoryIndex index.php

不幸的是,我的 php 脚本的一部分现在被破坏了。请记住,在修改我的 .htaccess 文件之前,一切正常。在登录页面上,我有一些脚本可以使用 POST 方法传递一些用户输入,如下所示:

<form method='POST' action='loginconfirm.php'>
Password: <input type='password' name='password'></input>
<input type='submit' name='submit' value='Go'></input>
</form>

在loginconfirm.php页面上,我有一个加密类作为页面中的包含文件,代码如下:

<?php
//source: http://stackoverflow.com/questions/2448256/php-mcrypt-encrypting-decrypting-file
class Encryption {

const CYPHER = MCRYPT_RIJNDAEL_256;
const MODE = MCRYPT_MODE_CBC;
const KEY = 'SecretKey';

public function encrypt($plaintext) {
$td = mcrypt_module_open(self::CYPHER, '', self::MODE, '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, self::KEY, $iv);
$crypttext = mcrypt_generic($td, $plaintext);
mcrypt_generic_deinit($td);
return rawurlencode(base64_encode($iv . $crypttext));
}

public function decrypt($crypttext) {
$crypttext = rawurldecode($crypttext);
$crypttext = base64_decode($crypttext);
$plaintext = '';
$td = mcrypt_module_open(self::CYPHER, '', self::MODE, '');
$ivsize = mcrypt_enc_get_iv_size($td);
$iv = substr($crypttext, 0, $ivsize);
$crypttext = substr($crypttext, $ivsize);
if ($iv) {
mcrypt_generic_init($td, self::KEY, $iv);
$plaintext = mdecrypt_generic($td, $crypttext);
}
return trim($plaintext);
}

}

//source: http://stackoverflow.com/questions/2448256/php-mcrypt-encrypting-decrypting-file
?>

我在页面上做的第一件事是设置一个新变量,该变量对密码进行了加密,如下所示:

<?php
include ("includefiles/EncryptionUtilities.php");
$passworde = Encryption::encrypt($_POST['password']);
setcookie('password', $passworde, time() + (60 * 5));
?>

正常情况下它可以正常工作,但现在它会抛出错误:

an empty string was passed into EncryptionUtilities.php, and cannot modify header information - headers already sent.

我认为 .htaccess 文件存在问题,不允许 POST 方法在页面之间进行通信。

最佳答案

使用外部重定向 POST 数据不会重定向并且会丢失。将您的 .php 规则替换为:

# Redirect external .php requests to extensionless url
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /.+?\.php [NC]
RewriteRule ^(.+?)\.php$ /$1 [R=301,L,NE]

关于php - 更改我的 .htaccess 文件后,我的 php 上的 POST 方法不再起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28518711/

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