I was trying to redirect an html page to two different php files.
Html file which i created is redirect.html
. When i go to that page it would check if i was logged in or not, if i was not it would take me to ucplogin.php
on the other hand if i was logged in it'd take me to ucphome.php
.
Here the problem is the code i'm trying is obviously messed up because i've been trying for a while and still doesnt work
<?php
session_start();
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="1;url=http://example.com">
<script type="text/javascript">
<?php
if(!isset($_SESSION['playername']))
{
?>
window.location.href = "http://localhost/working/ucplogin.php"
<?php
}
else
{
?>
window.location.href = "http://localhost/working/ucphome.php"
<?php
}
?>
</script>
<title>Page Redirection</title>
</head>
</html>
EDIT: I have seen all those answers and got some points but i rewrite the code to this
<?php
session_start();
?>
<?php
if(!isset($_SESSION['playername']))
{
?>
header('Location: http://localhost/working/ucplogin.php');
<?php
}
else
{
?>
header('Location: http://localhost/working/ucphome.php');
<?php
}
?>
when i go to redirect.php it gives me header('Location: http://localhost/working/ucphome.php'); when i'm logged in and this when i'm not header('Location: http://localhost/working/ucplogin.php');
Apparently it works but technically not, it doesn't redirect me to the exact page.