0

I have a ticketing website and I want to avoid users from opening index.php after they logged in. When they are logged in, they are automatically redirected to dashboard.php. Because my Login page is my index.php file and I want to customize it for login only. I want to write some code like below in PHP or jQuery or JavaScript:

<?php
    $call_user = $site_calls->call_user;
    if ($call_user <> 0){
        //redirect to ("dashboard.php");
    }
?>

If someone already logged in , they are redirected to dashboard.php whenever they want to access to index.php page.

Ram
  • 3,092
  • 10
  • 40
  • 56
Aria
  • 75
  • 1
  • 9

1 Answers1

1
`Simplest code, working shown below. Set a session variable after login, check for that session variable in index.php, if its set, redirect to dashboard.php`

    <?php
    session_start();
    if(isset($_SESSION["user"]))  //change to your session variable
    {
        header("Location: dashboard.php");
    }
    ?>

Unni Babu
  • 1,839
  • 12
  • 16
  • I was wondering if there was an advantage to the JS solution. I also added an answer using the `header`. – chris85 Jun 28 '15 at 15:45
  • yes i use script redirect because of this "header() must be called before any actual output is sent" :) – Unni Babu Jun 28 '15 at 15:46