php/html - http_referer
I am creating a website and on one particular page, am wanting to send the user back to the previous page. I am fairly new to PHP/HTML and have been using some existing code for ideas and help. The existing code uses the following method: if (! empty($HTTP_REFERER)) { header("Location: $HTTP_REFERER"); } else { header("Location: $CFG->wwwroot"); } However, when I use this code the HTTP_referer is always treated as empty and the user redirected to the root page. Any obvious flaws in this code? You need to use: $_SERVER['HTTP_REFERER'] Don't rely on the HTTP Referrer being a valid or even non