为什么 $_GET 不能在 nginx 服务器中工作,而是在 XAMPP localhost 中工作?

时间:2021-06-12 07:34:32

标签: php nginx nginx-config

我尝试了许多 stackoverflow 的答案来找到解决方案。但是我的代码在 localhost 上的 xampp 服务器上工作,但在 nginx 上不起作用。我正在缩短链接,但网址没有重定向。

    <?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;
          }

0 个答案:

没有答案
相关问题