implying the file name in php
hello everybody i have been asked to design a general login page (and others) for a website. what i need is when any user simply clicks on the website's name; the user is directly taken to the login page. the site is designed so that one cannot enter without being logged in. any 开发者_StackOverflow社区help will be appreciated.
thanks in advanceNot 100% sure what you are asking for here. From a quick read of the OP question, it appears you are wanting to direct people to the login page if they visit the main page and are not logged in.
To do this, all you need do is, in the main page, test whether the user is logged in. If they are not, then you redirect them to the login page.
<?php
// Within the INDEX.PHP file, at the very top
// - nothing can be infront of the opening tag for this PHP section.
session_start();
if( $_SESSION['loggedIn']!=true ){
header( 'Location: login.php' );
die();
}
This will redirect anyone viewing index.php to the login.php page, if they are not logged in. So long as, when they are logged in, you set $_SESSION['loggedIn']
to true
(otherwise everyone, everytime, will be sent to the login page).
精彩评论