Forum is shutting down, join us on Discord.

- No new threads can be created
- Shoutbox has been disabled
- All chat/support/market will be on Discord
- if you have a special status on forum (ie: staff, legendary user, etc), then PM Phoenix on forum with your Discord name to reclaim your status on Discord
See you all on Discord!


  
Go Back   Twilight MU Online Forum > Community > Programming Section

Programming Section All programming related stuff goes here.


Welcome to the Twilight MU Online Forum forums.

You are currently viewing our boards as a guest which gives you limited access. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

After registering you will receive an email with a confirmation link that you will need to click in order to activate your forum account.

NOTE: It's recommanded that you use on forum a different username and password than the game username and password.

If you have any problems with the registration process or your account login, please contact contact us.

 
 
Thread Tools Display Modes

login script problem :D
Old 21-12-2008   #1
albsky
I'm speshul x_X

 
albsky's Avatar
 
InGame Character:
My Mood:
albsky is offline
Points: 9,407, Level: 41
Points: 9,407, Level: 41 Points: 9,407, Level: 41 Points: 9,407, Level: 41
Level up: 80%, 93 Points needed
Level up: 80% Level up: 80% Level up: 80%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Rank: Platinum Member
Join Date: Jun 2008
Rep: albsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud of
Rep Power: 221
Casino Cash: 5538
Default login script problem :D

mooo, made my first login script lol.
nothing connected to Database but it's my first try
k, it's located here: http://albsky.110mb.com/login
details:
voorbeeld
voorbeeld
K, it works, it redirects you to 'usercp.php'.
But, you can go to usercp.php without logging in as well!
How do I let it require to be logged in? What is the code? A new session or what? what ^^
Can someone read the codes and tell me what to add/change/whatever

Codes from the 3 files;

---Index.php---
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
</head>

<body bgcolor="000000">
<font color="ffffff">
<h1>Login</h1>
<form method="post" action="login.php">
    <p>
        <label for="user">Username:</label>
        <input type="text" name="user" id="users" />
    </p>
    <p>
        <label for="pass">Password:</label>
        <input type="password" name="pass" id="pass" />
    </p>
    <p>
        <input type="submit" value="Login" />
    </p>
</form>
</font>
</body>
</html>
---login.php---
Code:
<?php
session_start();
$sGebruikerControle = 'voorbeeld';
$sWachtwoordControle = 'voorbeeld';
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(isset($_POST['user'], $_POST['pass']))
    {    
 $sGebruiker = trim($_POST['user']);
        $sWachtwoord = trim($_POST['pass']);
        if($sGebruiker == $sGebruikerControle && $sWachtwoord == $sWachtwoordControle)
        {
            $_SESSION['logged_in'] = true;
            $_SESSION['gebruiker'] = $sGebruiker;
            header('Refresh: 3; url=usercp.php');
            echo 'You have been succesfully logged in, please proceed, you will be redirected in 3 seconds!';
        }
        else
        {
            header('Refresh: 3; url=index.php');
            echo 'Wrong username and/or password!';
        }
    }
    else
    {
        header('Refresh: 3; url=index.php');
        echo 'Required field does not exist!';
    }
}
else
{
    header('Location: index.php');
    if(isset($_POST['user'], $_POST['pass']))
    {    
        $sGebruiker2 = trim($_POST['user']);
        $sWachtwoord2 = trim($_POST['pass']);
         if($sGebruiker2 == $sGebruikerControle2 && $sWachtwoord2 == $sWachtwoordControle2)
        {
            $_SESSION['logged_in'] = true;
            $_SESSION['gebruiker'] = $sGebruiker2;
            header('Refresh: 3; url=usercp.php');
            echo 'You have been succesfully logged in, please proceed, you will be redirected in 3 seconds!';
        }
        else
        {
            header('Refresh: 3; url=index.php');
            echo 'Wrong username and/or password!';
        }
    }
    else
    {
        header('Refresh: 3; url=index.php');
        echo 'Required field does not exist!';
    }
}

    exit();


?>
---UserCP.php---
Code:
<?
include 'login.php';
session_start()
$_SESSION['logged_in'] = true;
exit()
?>
<html>
<head>
<title></title>
</head>
<body bgcolor="ffffff">
<h3>Hoi</h3>
Hoi!
</body>
</html>
__________________
-----

 

Old 21-12-2008   #2
Judobreaker
GFX Master

 
Judobreaker's Avatar
 
InGame Character:
My Mood:
Judobreaker is offline
Points: 23,555, Level: 67
Points: 23,555, Level: 67 Points: 23,555, Level: 67 Points: 23,555, Level: 67
Level up: 8%, 645 Points needed
Level up: 8% Level up: 8% Level up: 8%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Sep 2006
Location: Holland
Age: 35
Rep: Judobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond repute
Rep Power: 341
Casino Cash: 10394
Default

You don't have to start a session in UserCP if you've already started one in login.php (cause you're including that).


login.php

Code:
<?php
session_start();
$sGebruikerControle = 'voorbeeld';
$sWachtwoordControle = 'voorbeeld';
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(isset($_POST['user'], $_POST['pass']))
    {    
 $sGebruiker = trim($_POST['user']);
        $sWachtwoord = trim($_POST['pass']);
        if($sGebruiker == $sGebruikerControle && $sWachtwoord == $sWachtwoordControle)
        {
            $_SESSION['logged_in'] = true;
            $_SESSION['gebruiker'] = $sGebruiker;
            header('Refresh: 3; url=usercp.php');
            echo 'You have been succesfully logged in, please proceed, you will be redirected in 3 seconds!';
        }
        else
        {
        $_SESSION['logged_in'] = false;
            header('Refresh: 3; url=index.php');
            echo 'Wrong username and/or password!';
        }
    }
    else
    {
        $_SESSION['logged_in'] = false;
    header('Refresh: 3; url=index.php');
        echo 'Required field does not exist!';
    }
}
else
{
    header('Location: index.php');
    if(isset($_POST['user'], $_POST['pass']))
    {    
        $sGebruiker2 = trim($_POST['user']);
        $sWachtwoord2 = trim($_POST['pass']);
         if($sGebruiker2 == $sGebruikerControle2 && $sWachtwoord2 == $sWachtwoordControle2)
        {
            $_SESSION['logged_in'] = true;
            $_SESSION['gebruiker'] = $sGebruiker2;
            header('Refresh: 3; url=usercp.php');
            echo 'You have been succesfully logged in, please proceed, you will be redirected in 3 seconds!';
        }
        else
        {
        $_SESSION['logged_in'] = false;
            header('Refresh: 3; url=index.php');
            echo 'Wrong username and/or password!';
        }
    }
    else
    {
    $_SESSION['logged_in'] = false;
        header('Refresh: 3; url=index.php');
        echo 'Required field does not exist!';
    }
}

    exit();


?>

UserCP.php

Code:
<?
include 'login.php';

if( $_SESSION['logged_in'] != true );
die();
?>

<html>
<head>
<title></title>
</head>
<body bgcolor="ffffff">
<h3>Hoi</h3>
Hoi!
</body>
</html>
__________________
[CENTER]
Thank you Jessie!

Visit my portfolio at http://www.rvantwerpen.com

FireStorm: tht i could be your bitch
FireStorm: you are and have done so much for us
Judobreaker: I dont feel very useful a lot though lol
 

Old 22-12-2008   #3
albsky
I'm speshul x_X

 
albsky's Avatar
 
InGame Character:
My Mood:
albsky is offline
Points: 9,407, Level: 41
Points: 9,407, Level: 41 Points: 9,407, Level: 41 Points: 9,407, Level: 41
Level up: 80%, 93 Points needed
Level up: 80% Level up: 80% Level up: 80%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Rank: Platinum Member
Join Date: Jun 2008
Rep: albsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud of
Rep Power: 221
Casino Cash: 5538
Default

hmm, I can still enter it without 'logging in' and when I log in I can't see it.
I've tried making the 'true' in usercp to 'false' and 'die' to 'exit'.
But in this way it doesn't work =S, you have any other suggestions
__________________
-----

 

Old 23-12-2008   #4
Judobreaker
GFX Master

 
Judobreaker's Avatar
 
InGame Character:
My Mood:
Judobreaker is offline
Points: 23,555, Level: 67
Points: 23,555, Level: 67 Points: 23,555, Level: 67 Points: 23,555, Level: 67
Level up: 8%, 645 Points needed
Level up: 8% Level up: 8% Level up: 8%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Sep 2006
Location: Holland
Age: 35
Rep: Judobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond repute
Rep Power: 341
Casino Cash: 10394
Default

well yeah lol...

Code:
<?
include 'login.php';

if( $_SESSION['logged_in'] != true ) {
    die();
}
?>

<html>
<head>
<title></title>
</head>
<body bgcolor="ffffff">
<h3>Hoi</h3>
Hoi!
</body>
</html>
Try that. :P
__________________
[CENTER]
Thank you Jessie!

Visit my portfolio at http://www.rvantwerpen.com

FireStorm: tht i could be your bitch
FireStorm: you are and have done so much for us
Judobreaker: I dont feel very useful a lot though lol
 

Old 27-12-2008   #5
albsky
I'm speshul x_X

 
albsky's Avatar
 
InGame Character:
My Mood:
albsky is offline
Points: 9,407, Level: 41
Points: 9,407, Level: 41 Points: 9,407, Level: 41 Points: 9,407, Level: 41
Level up: 80%, 93 Points needed
Level up: 80% Level up: 80% Level up: 80%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Rank: Platinum Member
Join Date: Jun 2008
Rep: albsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud ofalbsky has much to be proud of
Rep Power: 221
Casino Cash: 5538
Default

doesn't work, the problem is that it requires login.php which in some way makes you login again, so you login over and over and over again :P
__________________
-----

 

Old 29-12-2008   #6
miszmaniac1
...

 
miszmaniac1's Avatar
 
InGame Character:
miszmaniac1 is offline
Points: 6,766, Level: 35
Points: 6,766, Level: 35 Points: 6,766, Level: 35 Points: 6,766, Level: 35
Level up: 19%, 284 Points needed
Level up: 19% Level up: 19% Level up: 19%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Rank: Platinum Member
Join Date: Oct 2006
Location: Poland
Age: 41
Rep: miszmaniac1 has much to be proud ofmiszmaniac1 has much to be proud ofmiszmaniac1 has much to be proud ofmiszmaniac1 has much to be proud ofmiszmaniac1 has much to be proud ofmiszmaniac1 has much to be proud ofmiszmaniac1 has much to be proud ofmiszmaniac1 has much to be proud ofmiszmaniac1 has much to be proud ofmiszmaniac1 has much to be proud of
Rep Power: 237
Casino Cash: 347
Default

You guys, I've already told Albsky on Shoutbox, that he shouldn't do it this way. Login script is 1 thing, and another is auth check. Algorithm should work this way:
1. Check if user is authenticated
YES - go on,
NO - send him to login script.

If you load login.php script before checking it it's just not working.

IMAO the prettiest and still easy way to do this would be:
(lol, i've pressed post, instead of go advanced )
Code:
function authcheck() {
   if($_SESSION['userauth'] !== true ) {
      require('login.php');
      exit; 
   } 
   return true;
}
Now in all later script you have to include your library files (which you'll probably need to do anyway). This way, in all files which need user authentication you'll just use authcheck(); and that's it.

Ok, now that is working:

Code:
<?
session_start();
if(!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] != 1) {
    header('Location: index.php');
    exit();
}
?>
<html>
<head>
<title></title>
</head>
<body bgcolor="ffffff">
<h3>Hoi</h3>
Hoi!
</body>
</html>
__________________
IGN: miszmaniac, GrzesMG

Last edited by miszmaniac1; 29-12-2008 at 02:46 AM..
 

Old 29-12-2008   #7
Judobreaker
GFX Master

 
Judobreaker's Avatar
 
InGame Character:
My Mood:
Judobreaker is offline
Points: 23,555, Level: 67
Points: 23,555, Level: 67 Points: 23,555, Level: 67 Points: 23,555, Level: 67
Level up: 8%, 645 Points needed
Level up: 8% Level up: 8% Level up: 8%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Sep 2006
Location: Holland
Age: 35
Rep: Judobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond reputeJudobreaker has a reputation beyond repute
Rep Power: 341
Casino Cash: 10394
Default

Yeah lol, that would probably do the trick. xD
I tried editing his code which is a bit harder... :P
__________________
[CENTER]
Thank you Jessie!

Visit my portfolio at http://www.rvantwerpen.com

FireStorm: tht i could be your bitch
FireStorm: you are and have done so much for us
Judobreaker: I dont feel very useful a lot though lol
 
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -5. The time now is 05:49 PM.



vBulletin skin developed by: eXtremepixels
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright ©2006 - 2019 Twilight MU. All Rights Reserved