Agel Salazar Agel Salazar - 1 year ago 206
Javascript Question

Javascript: header is not defined

I already tried the 2 re-directions in JavaScript, the

but always show me an error:

ReferenceError: header is not defined

My code from PHP:

echo "<script> header('location: index.php');</script>";

Answer Source

There's no header() function in JavaScript. header() is a PHP function. Here is one way to redirect using JS:

echo "<script> window.location.href = 'index.php'; </script>";

Or in PHP:

header('Location: index.php');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download