Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-14-2010, 07:03 PM   PM User | #1
simolokid
New Coder

 
Join Date: Jan 2010
Posts: 29
Thanks: 1
Thanked 1 Time in 1 Post
simolokid is an unknown quantity at this point
Login system bugging.

Hi people,

I've been working on a site, which I'm now going to create a management system for, but I'm already stuck on the login-system lol.

It keeps itself at admin.php, haven't got a clue why since it doesn't give any errors.. ;<

Any help is appreciated.

Admin.php
PHP Code:
<?php
session_start
();
if(
$_SESSION['id']){
    echo 
'session';
}
if(
$_POST['inloggen']){
    
$link mysqli_connect('localhost''dbname''pw',something');
    if (!$link){
        //Indien de connectie mislukt stop dan het script en laat een error zien.
        die('
<h1 style="color:red">Connectie naar de database is niet gelukt!</b>');
    }
    if(empty($_POST['
naam'])){
        $msg .= "U heeft geen gebruikersnaam ingevuld. <br />";
    }
    elseif(empty($_POST['
wachtwoord'])){
        $msg .= "U heeft geen wachtwoord ingevuld. <br />";
    }
    else{
    $gebruikersnaam = $_POST['
naam'];
    $wachtwoord = $_POST['
wachtwoord'];
    $gebruikersnaam = mysqli_real_escape_string($link, $gebruikersnaam);
    $wachtwoord = mysqli_real_escape_string($link, $wachtwoord);
    $wachtwoord = sha1($wachtwoord);
    $query = mysqli_query($link,"SELECT id,gebruikersnaam,wachtwoord 
                                        FROM AFGM_leden
                                         WHERE gebruikersnaam = '
$gebruikersnaam'
                                            AND wachtwoord = '
$wachtwoord'");
        if($query)
        $result = mysqli_num_rows($query);
        else{
            $msg .= "query mislukt<br />";
        }
        if($result > 0){
            $_SESSION['
id'] = $result['id'];
            $_SESSION['
gebruikersnaam'] = $result['gebruikersnaam];
            
header("location: index.php");
        }
        else{
            
$msg .= "Onbekende combinatie van gebruikersnaam en wachtwoord, probeert u het later nog eens. <br />";
        }
    }
}
else{
?>
<!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>Inlogsysteem AFGM website</title>
<link href="style.css" rel="stylesheet" type="text/css" />

</head>

<body>
<div id="box">
<div id="titel">
Inlogsysteem AFGM Back-end Website
</div>
<div id="body">
<form method="post" action="" >
<table>
<tr><td><label for="naam">Naam: </label></td><td><input type="text" name="naam" value="" /></td></tr>
<tr><td><label for="wachtwoord">Wachtwoord: </label></td><td><input type="text" name="wachtwoord" value="" /></td></tr>
<tr><td>&nbsp;</td><td><input type="submit" name="inloggen" value="Log in" /></td></tr>
</table>
</form>
<?php 
if(!empty($msg)){
    echo 
"$msg <br />";
}
?>
</div>
<div id="footer">
Copyright (C) AFGM - 2010, Made by simolokid.
</div>
</div>
</body>
</html>
<?php }?>
index.php
PHP Code:
<?php
if(!$_SESSION['id']){
    
header("location: admin.php");
}
else{
?>*html*
simolokid is offline   Reply With Quote
Old 02-14-2010, 07:39 PM   PM User | #2
simolokid
New Coder

 
Join Date: Jan 2010
Posts: 29
Thanks: 1
Thanked 1 Time in 1 Post
simolokid is an unknown quantity at this point
Quote:
previous post
Ok, I have now achieved to do all kinds of controle structures, navigate to index.php and actually just gain acces without logging in....

Think it's time for a break xD

Blegh >.<

Any tips? :<

Last edited by simolokid; 02-14-2010 at 07:50 PM..
simolokid is offline   Reply With Quote
Old 02-14-2010, 07:53 PM   PM User | #3
bdl
Regular Coder

 
Join Date: Apr 2007
Location: Camarillo, CA US
Posts: 590
Thanks: 4
Thanked 83 Times in 82 Posts
bdl is an unknown quantity at this point
PHP Code:
if($query)
        
$result mysqli_num_rows($query);
        else{
            
$msg .= "query mislukt<br />";
        }
        if(
$result 0){
            
$_SESSION['id'] = $result['id'];
            
$_SESSION['gebruikersnaam'] = $result[gebruikersnaam];
            
header("location: index.php");
        } 
Take a closer look at that. Where does $result come from? Is it an array containing the resultset data, e.g. the `id` field value, etc? You're missing a crucial step there.
bdl is offline   Reply With Quote
Old 02-15-2010, 08:38 AM   PM User | #4
iLochie
Regular Coder

 
Join Date: Jan 2010
Posts: 101
Thanks: 17
Thanked 5 Times in 5 Posts
iLochie is an unknown quantity at this point
Gah, I hate code in different languages. :P Anyways, you should be using mysql_fetch_array to get the info. For example, below the $result line, use this:
PHP Code:
$info mysql_fetch_array($query); 
Then change the session variables to whatever = $info[whatever]

That should work, cheers.
iLochie is offline   Reply With Quote
Old 02-15-2010, 11:24 AM   PM User | #5
simolokid
New Coder

 
Join Date: Jan 2010
Posts: 29
Thanks: 1
Thanked 1 Time in 1 Post
simolokid is an unknown quantity at this point
Quote:
Originally Posted by iLochie View Post
Gah, I hate code in different languages. :P Anyways, you should be using mysql_fetch_array to get the info. For example, below the $result line, use this:
PHP Code:
$info mysql_fetch_array($query); 
Then change the session variables to whatever = $info[whatever]

That should work, cheers.
PHP Code:
<?php
session_start
();
if(
$_POST['inloggen']){
    
$link mysqli_connect('*craperdecrap*);
    if (!$link){
        //Indien de connectie mislukt stop dan het script en laat een error zien.
        die('
<h1 style="color:red">Connectie naar de database is niet gelukt!</b>');
    }
    if(empty($_POST['
naam'])){
        $msg .= "U heeft geen gebruikersnaam ingevuld. <br />";
    }
    elseif(empty($_POST['
wachtwoord'])){
        $msg .= "U heeft geen wachtwoord ingevuld. <br />";
    }
    if(!empty($msg)){
        header("location: admin.php");
        echo "$msg";
    }
    else{
    $gebruikersnaam = $_POST['
naam'];
    $wachtwoord = $_POST['
wachtwoord'];
    $gebruikersnaam = mysqli_real_escape_string($link, $gebruikersnaam);
    $wachtwoord = mysqli_real_escape_string($link, $wachtwoord);
    $wachtwoord = sha1($wachtwoord);
    $query = mysqli_query($link,"SELECT id,gebruikersnaam,wachtwoord 
                                        FROM AFGM_leden
                                         WHERE gebruikersnaam = '
$gebruikersnaam'
                                            AND wachtwoord = '
$wachtwoord'");
        if($query)
        $result = mysqli_fetch_array($query);
        else{
            $msg .= "query mislukt<br />";
        }
        if(!empty($result)){
            $_SESSION['
id'] = $result['id'];
            $_SESSION['
gebruikersnaam'] = $result['gebruikersnaam];
            
header("location: index.php");
        }
        else{
            
$msg .= "Onbekende combinatie van gebruikersnaam en wachtwoord, probeert u het later nog eens. <br />";
        }
    }
}
else{
?>
<!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>Inlogsysteem AFGM website</title>
<link href="style.css" rel="stylesheet" type="text/css" />

</head>

<body>
<div id="box">
<div id="titel">
Inlogsysteem AFGM Back-end Website
</div>
<div id="body">
<form method="post" action="" >
<table>
<tr><td><label for="naam">Naam: </label></td><td><input type="text" name="naam" value="" /></td></tr>
<tr><td><label for="wachtwoord">Wachtwoord: </label></td><td><input type="text" name="wachtwoord" value="" /></td></tr>
<tr><td>&nbsp;</td><td><input type="submit" name="inloggen" value="Log in" /></td></tr>
</table>
</form>
<?php 
if(!empty($msg)){
    echo 
"$msg <br />";
}
?>
</div>
<div id="footer">
Copyright (C) AFGM - 2010, Made by simolokid.
</div>
</div>
</body>
</html>
<?php }?>
that's admin.php

index.php:
PHP Code:
<?php
if(!$_SESSION['id']){
    
header("location: admin.php");
}
else{ *
html*
?>
And it's still not working ! >.<
simolokid is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 08:38 PM.


Advertisement
Log in to turn off these ads.