user3855851
user3855851

Reputation: 175

PHP header reloads current page instead

I am trying to redirect to some page after php processing. Sometimes it works fine and it redirects to the next page but 50% of the time it just reloads the same page again.

I have tried different things like ob_clean(), ob_flush() before redirecting but it didnot work

function util_redirect ($page)
{
    ob_start();
    header("Location: " . $page,true,302);
    ob_end_flush();
    die(1);

}

Expected: redirects to the next page Actual: Reloads current page instead

Upvotes: 1

Views: 50

Answers (2)

iamatstackoverflow
iamatstackoverflow

Reputation: 402

Try this and I think this will work

function util_redirect ($page){
    header('Location: '.$page, TRUE, 302);
} 

Upvotes: 1

Samuel Dike Omaka
Samuel Dike Omaka

Reputation: 1

I think you can achieve it this way without complexity or 50% error

function util_redirect ($page){
   header("Location: " . $page);
}

Upvotes: 0

Related Questions