Unable to redirect after login in using $_SERVER['HTTP_REFERER'] in php

时光怂恿深爱的人放手 提交于 2020-02-06 08:06:23

问题


I want my user to redirected to page where user clicked login so i added following code to config file so that each and ever file has access to redirect code

config.php

if (isset($_SERVER['HTTP_REFERER']) && basename($_SERVER['HTTP_REFERER']) != basename($_SERVER['PHP_SELF'])) {
    $_SESSION['redirect_url'] = $_SERVER['HTTP_REFERER'];
}

So that when ever i need a redirect i can simple call like bellow

header('location:' . $_SESSION['redirect_url']);
exit();

and when i try above code i get error showing

ERR_TOO_MANY_REDIRECTS

i even tried echo $_SESSION['redirect_url'] and it showed a valid requested URL

But it doesn't redirected. Can some one help me what wrong im doing.

and here is

.htaccess

RewriteEngine On

# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]

来源:https://stackoverflow.com/questions/59972656/unable-to-redirect-after-login-in-using-serverhttp-referer-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!