eddiecore Posted November 16, 2011 Share Posted November 16, 2011 I'm trying to create a website so that if I go to http://websiteaddress.com/, it will go to then index and if you are already logged in it will display the main page, but if you aren't logged in it'll show a login/registration page. Also, how does the following work: index.php?action=home index.php?action=register They show two seperate pages? So, could it go to the home page if logged in, but if not logged in it'll go the registration/login page? Quote Link to comment https://forums.phpfreaks.com/topic/251272-need-some-basic-help/ Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2011 Share Posted November 16, 2011 And where are you stuck? Have you written any code for this yet? Quote Link to comment https://forums.phpfreaks.com/topic/251272-need-some-basic-help/#findComment-1288782 Share on other sites More sharing options...
eddiecore Posted November 16, 2011 Author Share Posted November 16, 2011 And where are you stuck? Have you written any code for this yet? No, I just want to understand how those two things would work. Oh, I understand! I'm trying to make php templates. I think I'm able to figure out something for what I'm trying to do. I'll just use php to verify I'm logged in using cookies and if I'm logged in it'll call up the mainpage template. Quote Link to comment https://forums.phpfreaks.com/topic/251272-need-some-basic-help/#findComment-1288783 Share on other sites More sharing options...
QuickOldCar Posted November 17, 2011 Share Posted November 17, 2011 Use sessions. At the top of every page you start the session and check for logged in user. If are already logged in do nothing. If not a logged in user can then redirect them to a registration page. After registration redirect them back to either a login page, or the main page that contains a login. Quote Link to comment https://forums.phpfreaks.com/topic/251272-need-some-basic-help/#findComment-1288839 Share on other sites More sharing options...
phporcaffeine Posted November 17, 2011 Share Posted November 17, 2011 Here is how the most basic of basic login scripts would look, using sessions: We'll call this index.html: <html> <head><title>Test</title></head> <body> <form name="loginFrm" id="loginFrm" action="login.php" method="post"> Enter the secret code: <input type='password' name='code' id='code'> <input type='submit' name='send' id='send' value='Login'> </form> </body> </html> We'll call this login.php: <?php session_start(); //GOOD HABIT SAYS ALWAYS PUT THIS AT THE TOP, BEFORE ANYTHING ELSE if (isset($_POST['password'])) { if ( strtolower( trim( stripslashes($_POST['password']) ) ) === 'test') { $_SESSION['login'] = 'John Doe User'; } else { die(session_destroy()); } } if (isset($_SESSION['login'])) { print_r($_SESSION['login']); } ?> If you type in 'test' (no quotes) as the secret code, you'll see 'John Doe User' from login.php, anything else and you won't see anything. *NOTE* The above html page and php script is a DEMO, to help you understand the basics. It is not suited to use in an actual production system, but will suffice for getting your head around the basics. To answer your other question: index.php?action=home As far as PHP is concerned; the above is part of a url, everything to the right of '?' are key/value pairs in the GET namespace. So, if the page 'index.php' were reached with this URL, the array element $_GET['action'] would hold the value 'home'. Quote Link to comment https://forums.phpfreaks.com/topic/251272-need-some-basic-help/#findComment-1288901 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.