php - 为什么 $_GET 不在 nginx 服务器中工作,但在 XAMPP localhost 中工作?
问题描述
我已经尝试了许多 stackoverflow 答案来找到解决方案。但是我的代码在 localhost 上的 xampp 服务器上运行,但在 nginx 上不起作用。我正在缩短链接,但 url 没有重定向。
<?php
include "php/config.php";
$new_url = "";
if(isset($_GET)){
foreach($_GET as $key=>$val){
$u = mysqli_real_escape_string($conn, $key);
$new_url = str_replace('/', '', $u);
}
$sql = mysqli_query($conn, "SELECT full_url FROM url WHERE shorten_url = '{$new_url}'");
if(mysqli_num_rows($sql) > 0){
$sql2 = mysqli_query($conn, "UPDATE url SET clicks = clicks + 1 WHERE shorten_url = '{$new_url}'");
if($sql2){
$full_url = mysqli_fetch_assoc($sql);
echo $full_url['full_url'];
header("Location:".$full_url['full_url']);
}
}
}
?>
我还编辑了 nginx 站点可用文件
location / {
try_files $uri $uri/ /index.html /index.php?$args /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
解决方案
推荐阅读
- selenium-webdriver - protractor/webDriver 中的 isDisplayed() 是如何工作的?
- performance - 需要一种方法来创建多个(例如每个 250 个)google 和 Outlook 测试帐户,以对 oauth 相关的 api 进行负载测试。(例如:gmail api)
- neo4j - 类型不匹配:已使用冲突类型 Any(预期节点)定义了 connectedcompany
- regex - 正则表达式如果第二个参数是注册
- python - 实时检查 2 个 QLineEdits 文本
- python - 访问熊猫数据框中的单元格
- python - CUDA 目标的 Numba 和 guvectorize:代码运行速度比预期慢
- vaadin - 为什么 setDefaultErrorHandler 在 vaadin 流程中使我的视图崩溃?
- javascript - 触发 onbeforeunload 事件的所有可能原因是什么?
- python - 在 numpy 数组的副本中交换元素