javmen Posted April 18, 2014 Share Posted April 18, 2014 i need help with a login i have on my site. I'm new to this so i dont know if i'll get any help Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted April 18, 2014 Share Posted April 18, 2014 How could we possibly help you when you don't post any code? Quote Link to comment Share on other sites More sharing options...
javmen Posted April 18, 2014 Author Share Posted April 18, 2014 http://paste.ee/p/tscSmlook at those two php files.its login system on an online game which uses accounts from a gameIt works. I'd like to fix it up a bit. I wanna make it to where for example if someone goes to example.com/HOME , home will redirect to thelogin page if they are not logged in with THAT login system i gave you! if someone is logged in they have access to all pages, example/fds etc etc. I know something about sessions but how would you go on about doing it with those logins i provided. I wanna block out ALL my pages UNLESS logged in. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted April 18, 2014 Share Posted April 18, 2014 The link you provided does not work. But basically you need to use sessions. When the user successfully logs in you set a logged in flag $_SESSION['loggedIn'] = true; // do this when user has logged in Now at the top of each page you only want only logged in users to see you'd do something like <?php session_start(); // check if user is logged in if(!isset($_SESSION['loggedIn']) || (isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] !== true)) { // user not logged in, redirect to the login page header('Location: /path/to/login_page/'); exit(); // kill the script } // user is logged in, display the restricted content To log the user out, you unset the $_SESSION['loggedIn'] variable. Quote Link to comment Share on other sites More sharing options...
javmen Posted April 18, 2014 Author Share Posted April 18, 2014 here is the game's login/ system . http://pastebin.com/yTQNH02A that should be a better explaination please help if possible a friend of mine did it Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted April 18, 2014 Share Posted April 18, 2014 That link does not work either. Just post the code here in tags or just attach the necessary files to this post. Quote Link to comment Share on other sites More sharing options...
javmen Posted April 19, 2014 Author Share Posted April 19, 2014 login.phpzwinky.class.php Quote Link to comment Share on other sites More sharing options...
javmen Posted April 19, 2014 Author Share Posted April 19, 2014 there you go please help me, thank you. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted April 19, 2014 Share Posted April 19, 2014 The zwinky class has a method called authenticate_login() which you can use to check to see if the user is logged in. So in the pages you want the user to be logged in you'll have these two lines at the top of the page after the opening php tag require 'zwinky.class.php'; // require zwinky zwinky::authenticate_login(); // authenticates user, redirects user to login.php if they are not logged in. Quote Link to comment Share on other sites More sharing options...
javmen Posted April 19, 2014 Author Share Posted April 19, 2014 It puts the page i want blocked out blank. Are you sure i'm not missing anything in zwinky.class for it to work? Quote Link to comment Share on other sites More sharing options...
javmen Posted April 19, 2014 Author Share Posted April 19, 2014 <?php require 'zwinky.class.php'; // require zwinky zwinky::authenticate_login(); // authenticates user, redirects user to login.php if they are not logged in. is added to the top of a random page and it puts the page white. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted April 19, 2014 Share Posted April 19, 2014 Umm, not sure but looking at zwinky.class.php there appears to be a closing brace missing at the end of the file. After line 51 add a } Quote Link to comment Share on other sites More sharing options...
javmen Posted April 19, 2014 Author Share Posted April 19, 2014 okay so i have this page random name , hello.php i put this on top <?php require 'zwinky.class.php'; // require zwinky zwinky::authenticate_login(); // authenticates user, redirects user to login.php if they are not logged in. ?> and on my zwinky.class : // Authenticate login function. public static function authenticate_login() { session_start(); if ( !isset($_SESSION['username']) | !isset($_SESSION['password']) | !isset($_SESSION['session']) ) { header('Location: login.php'); } } okay when i go on the page hello.php for example yes it shows the login form of course cause i am not logged in and it redirects to login.php BUT i login and it refreshes and doesnt leave the login.php, also when i go straight to the login it wont go to the hello.php cause its somehow leading it back even though i enter correct details Quote Link to comment Share on other sites More sharing options...
javmen Posted April 19, 2014 Author Share Posted April 19, 2014 Look i updated the files, the zbucks.php is the page i want to lock out for example. I added the code you asked me too read my previous messages, if you could test it out i have usernames and passwords? zbucks.php zwinky.class.php login.php Quote Link to comment 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.