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!
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.
|
 |
login script problem :D |
 |
21-12-2008
|
#1
|
I'm speshul x_X
InGame Character:
My Mood:
albsky is offline
Level up: 80%, 93 Points needed |
Rank: Platinum Member
Join Date: Jun 2008
Rep Power: 232
Casino Cash: 5538
|
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>
__________________
-----

|
|
|
 |
|
 |
21-12-2008
|
#2
|
GFX Master
InGame Character:
My Mood:
Judobreaker is offline
Points: 23,555, Level: 67 |
Level up: 8%, 645 Points needed |
Join Date: Sep 2006
Location: Holland
Age: 36
Rep Power: 353
Casino Cash: 10394
|
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!
|
|
|
22-12-2008
|
#3
|
I'm speshul x_X
InGame Character:
My Mood:
albsky is offline
Level up: 80%, 93 Points needed |
Rank: Platinum Member
Join Date: Jun 2008
Rep Power: 232
Casino Cash: 5538
|
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   
__________________
-----

|
|
|
23-12-2008
|
#4
|
GFX Master
InGame Character:
My Mood:
Judobreaker is offline
Points: 23,555, Level: 67 |
Level up: 8%, 645 Points needed |
Join Date: Sep 2006
Location: Holland
Age: 36
Rep Power: 353
Casino Cash: 10394
|
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!
|
|
|
27-12-2008
|
#5
|
I'm speshul x_X
InGame Character:
My Mood:
albsky is offline
Level up: 80%, 93 Points needed |
Rank: Platinum Member
Join Date: Jun 2008
Rep Power: 232
Casino Cash: 5538
|
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
__________________
-----

|
|
|
 |
|
 |
29-12-2008
|
#6
|
...
InGame Character:
miszmaniac1 is offline
Level up: 19%, 284 Points needed |
Rank: Platinum Member
Join Date: Oct 2006
Location: Poland
Age: 42
Rep Power: 248
Casino Cash: 347
|
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..
|
|
|
29-12-2008
|
#7
|
GFX Master
InGame Character:
My Mood:
Judobreaker is offline
Points: 23,555, Level: 67 |
Level up: 8%, 645 Points needed |
Join Date: Sep 2006
Location: Holland
Age: 36
Rep Power: 353
Casino Cash: 10394
|
Yeah lol, that would probably do the trick. xD
I tried editing his code which is a bit harder... :P
__________________
[CENTER]
Thank you Jessie!
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:50 PM. |
|
|
|
|