I already tried the 2 re-directions in JavaScript, the window.location.href()
and header()
but always show me an error:
ReferenceError: header is not defined
My code from PHP:
echo "<script> header('location: index.php');</script>";
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');
exit;
you dont need to use jquery try this
echo header('Location: index.php');
exit;
You can easily achieve with Below Code:
For JavaScript in PHP:
echo '<script>window.location.href="YOURURL.COM"</script>';
For Simple PHP:
echo header('Location: '."YOURURL.COM");
header()
is a php function. and header()
must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
<?php
header("Location: index.php"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
ref: http://php.net/manual/en/function.header.php
in js try, window.location.href = "index.php"
//redirectUrl