0

I have an <a href="cookieaccept.php?accept=yes"> that links to a php file with this code:

<?php
    function goback()
    {
        header('Location: ' . $_SERVER['HTTP_REFERER']);
        exit;
    }
    $option = @$_GET['accept'];
    if(!empty($option)) // If user enter with some value
    {
        if($option== "yes")
        {
            setcookie("cookieaccept", "yes", time()+2592000, "/");
            goback();
        } else if($option=="no") {
            header('Location: ' . $_SERVER['HTTP_REFERER']);
            exit;
        } else {
            echo "Error... !"; //If it comes with value other than yes or no
        }
    } else {
        echo "Error... !"; // If it comes with no value at all
    }
?>

After clicking on the accept button i want the current page to refresh. But because the action takes place in a separate php file i can't get this to work... I tried with history back, refresh but i need some help with this one please.

Regards, Robert

Gautam D
  • 330
  • 3
  • 15
n00bly
  • 395
  • 6
  • 21
  • Have you tried to trigger your `cookieaccept.php` script from an ajax call? This way, depending on the response, you are already on the good page and just need to `localtion.reload()` in javascript. AFAIK, referer from `$_SERVER` [can't be trusted all the time](https://stackoverflow.com/a/5934784/7393478) – Kaddath May 09 '18 at 09:29
  • @Kaddath I haven't tried triggering the cookieaccept.php from an Ajax call, I have no idea how to achieve such thing... :( – n00bly May 09 '18 at 10:41

0 Answers0