Reputation: 68
Looked around at other posts but still struggling. Currently got a CRM system going. User starts off in /index.php.
<?php
include_once'header.php';
?>
<section class="main-container">
<div class="main-wrapper">
<h2>Motoko</h2>
<?php
if (isset($_GET["msg"]) && $_GET["msg"] == 'failed') {
echo "Incorrect Username/Password";
}
else { if (empty($uid) || empty($pwd))
echo "You are not logged in";
}
?>
</div>
</section>
<?php
include_once 'footer.php';
?>
Whereby /header.php contains:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Motoko</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<header>
<nav>
<div class="main-wrapper">
<ul>
<li><a href="index.php">Home</a></li>
</ul>
<div class="nav-login">
<?php
if (isset($_SESSION['u_id'])){
echo '<form action="includes/logout.inc.php" method="POST">
<button type="submit" name="submit">Logout</button>
</form>';
} else {
echo '<form action="includes/login.inc.php" method="POST">
<input type="text" name="uid" placeholder="Username/e-mail">
<input type="password" name="pwd" placeholder="password">
<button type="submit" name="submit">Login</button>
</form>';
echo '<form action="signup.php" method="POST">
<button type="submit">Sign up</button>
</form>';
echo '<form action="reset.php" method="POST">
<button type="submit">Forgot your Password?</button>
</form>';
}
?>
</div>
</div>
</nav>
</header>
I need to add something like if (isset($_SESSION['u_uid'])) header("Location: to where you would be redirected when you log in --> view.php)
I'm not sure where the statement should go. And if there is any other syntax that needs to be added.
Many thanks!
Upvotes: 1
Views: 40
Reputation: 1139
If I understand correctly, this code will help you.
if (isset($_SESSION['u_uid']))
echo ('<script type="text/javascript">window.location.replace("http://yoursite.com/yourpath.php");</script>');
Upvotes: 1