Jump to content

php login fix/edit


javmen

Recommended Posts

http://paste.ee/p/tscSm

look at those two php files.
its login system on an online game which uses accounts from a game

It 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 the
login 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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.