Redirect to different page if already opened before

24
February 11, 2019, at 5:50 PM

So I've created a login/signup system and have it if when you go to the homepage straight away it'll redirect you to the login page etc. But I'm trying to create an intro/tutorial stage when you signup and login for the first time. I can't figure out how to do it since I'm pretty much a noob at this sort of thing. I need help to be quite in-depth as well since I already stated I'm a noob at this thing, but any help you give is greatly appreciated. Thanks!

I've tried searching around to find something like this but I've found no results in depth enough for me.

Start of login.php:

<?php
// Initialize the session
session_start();
// Check if the user is already logged in, if yes then redirect to homepage
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){
    header("location: ../get-started/");
    exit;
}
// Include config file
require_once "secure/data/accounts.php";
// Define variables and initialize with empty values
$username = $password = "";
$username_err = $password_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){

Redirect user to tutorial page (mandatory at the moment):

                            // Store data in session variables
                            $_SESSION["loggedin"] = true;
                            $_SESSION["id"] = $id;
                            $_SESSION["username"] = $username;                            
                            // Redirect user
                            header("location: ../get-started/");
                        } else{
                            // Display an error message if password is not valid
                            $password_err = "The password you entered was not valid.";
                        }
                    }
                } else{
                    // Display an error message if username doesn't exist
                    $username_err = "No account found with that username.";
                }
            } else{
                echo "Oops! Something went wrong. Please try again later.";
            }
        }
        // Close statement
        mysqli_stmt_close($stmt);
    }
    // Close connection
    mysqli_close($link);
}
?>

I'm hoping to have a part where it checks if you have already seen the tutorial page before, and if you have it will redirect you straight to the home page.

I currently just have it to just go straight to the tutorial page as I have no clue how to set it up.

Answer 1

Right, in the end, I am using a system to add a cookie for the first time you visit it. Then each time you visit it, if you have the cookie it gave you it will redirect you to the main homepage.

I explained it in a messy way but I'm sure you get point. And to the people that commented, thanks for commenting to help me out! I have provided an example of the code I used below:

Example:

<?php
if (!isset($_COOKIE['tutorial']))
{
    setcookie("tutorial", "no");
    header('Location: example-intro.php');
    exit();
}
else
{
    header('Location: example-home.php');
    exit();
}
?>
READ ALSO
what should i avoid while coding in php

what should i avoid while coding in php

I just start learning php, while I was learning I stopped for a minute and I said: Why don't I write my own php script before I move on to the PHP-SQL?

34
How to redirect users to their specific subfolders?

How to redirect users to their specific subfolders?

Ok, so I tried to Google it, make it by myself, but I just messed up my website, so after days of trying, I'm here to ask

48