Detect if cookies are enabled in PHP
<p>I am trying to detect if a user on my page has cookies enabled or not. The following code performs the check, but, I have no idea on how to redirect the user to the page they came from.</p>

<p>The script starts a session and checks if it has already checked for cookies. If not, it redirects the user to a test page, and since I had called session_start() in the first page, I should see the PHPSESSID cookie if the user agent has cookies enabled.</p>

<p>The problem is, ths script might be called from any page of my site, and I will have to redirect them back to their selected page, say index.php?page=news&amp;postid=4.</p>

<pre><code>session_start();
// Check if client accepts cookies //
if (!isset($_SESSION['cookies_ok'])) {
    if (isset($_GET['cookie_test'])) {
        if (!isset($_COOKIE['PHPSESSID'])) {
            die('Cookies are disabled');
        } else {
            $_SESSION['cookies_ok'] = true;
            header(-------- - ? ? ? ? ? -------- -);
            exit();
        }
    }
    if (!isset($_COOKIE['PHPSESSID'])) {
        header('Location: index.php?cookie_test=1');
        exit();
    }
}
</code></pre>
