[PHP] Hulp nodig met function

Gestart doorJosnl6 reacties31 weergaven

7 berichten · pagina 1 van 1

Josnl

Lid · Topicstarter

Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Heey allemaal!

Ik heb een functie gemaakt in PHP die moet checken of er een sessie/cookie is aangemaakt, en als dat niet zo is word er geen toegang verleend tot het admingedeelte en als er wel een sessie/cookie is dan krijg je wel toegang.

Helaas werkt het volgende niet:

[COLOR= #0000BB]<?php
$account_naam[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]admin[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$account_wachtwoord[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]test123[/COLOR][COLOR= #007700];

function[/COLOR] checkLogin[COLOR= #007700]()
{[/COLOR]

    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]$account_naam[/COLOR][COLOR= #007700]]) &&[/COLOR] [URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_COOKIE[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]AdminSessie[/COLOR][COLOR= #007700]]))
    {[/COLOR]
        
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]U heeft niet de rechten om deze pagina te bekijken, u kunt <a href="login.php">hier</a> inloggen.[/COLOR][COLOR= #007700];
        
    }[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
        
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Welkom op het beheerpaneel!<br /><br />Kies hieronder uit een van de mogelijkheden om iets op de website te plaatsen:[/COLOR][COLOR= #007700];
        
    }

}[/COLOR]
?>


Dit is het logingedeelte:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]Inloggen[/COLOR][COLOR= #007700]])){[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #0000BB]$account_naam[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #0000BB]$account_wachtwoord[/COLOR][COLOR= #007700]){[/COLOR]
    
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<div class="goed">U bent succesvol ingelogd, u word zo doorgestuurd naar het beheerpaneel.</div>[/COLOR][COLOR= #007700];[/COLOR]
        
                [COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]$account_naam[/COLOR][COLOR= #007700]];[/COLOR]
                [URL="http://www.php.net/setcookie"]setcookie[/URL][COLOR= #007700]([/COLOR]AdminSessie[COLOR= #007700],[/COLOR] [COLOR= #0000BB]$account_naam[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/time"]time[/URL][COLOR= #007700]()+[/COLOR][COLOR= #0000BB]3600[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]24[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"refresh: 3; url=admin.php"[/COLOR][COLOR= #007700]); 
    
}[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<div class="fout">U heeft onjuiste gegevens ingevuld, probeer het nog een keer!</div>[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"refresh: 3;"[/COLOR][COLOR= #007700]);
    
    }
}[/COLOR]


?>

<div style="margin-left: auto; margin-right: auto; padding-top: 0px;">
<center>
<form method="post" action="">
<table border="0">
  <tr>
    <td>Gebruikersnaam:</td>
    <td>
      <input type="text" name="naam" size="25px">
    </td>
  </tr>
  <tr>
    <td>Wachtwoord</td>
    <td><input type="password" name="wachtwoord" size="25px"></td>
  </tr>
</table>
<input type="submit" value="inloggen" name="Inloggen">
</form>
</center>
</div>
?>


Oja, het is maar met één gebruiker, vandaar dat ik die gegevens gewoon in een string zet in niet in de database.

Ik hoop dat iemand me kan helpen!

Alvast bedankt,

Groetjes Josbiggrin
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
isset($_SESSION[$account_naam]) kan niet. Een var in dubbele quotes, of geen quotes.

Dus:

isset($_SESSION["$account_naam"])

Of nog beter:

isset($_SESSION[$account_naam])
0
Josnl

Lid · Topicstarter

Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dus dan moet het werken?

Edit: Werkt nog niet. Iemand een idee hoe dit te doen?smile
0
Berichten
544
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Zoek de verschillen wink
$_SESSION[$account_naam]

$_SESSION[account_naam]
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Geen de sessie een waarde inplaats van hem alleen aanmaken!
Dus gewoon:
$_SESSION[account_naam] = 1;
Dat werkt wss, en je hebt de checks ook verkeerd, als je bent ingelogd en een admin sessie hebt geeft hij nu aan dat het verkeerd is!
0
Berichten
544
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$account_naam[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]admin[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$account_wachtwoord[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]test123[/COLOR][COLOR= #007700];

function[/COLOR] checkLogin[COLOR= #007700]()
{[/COLOR]

    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]account_naam[/COLOR][COLOR= #007700]]) &&[/COLOR] [URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_COOKIE[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]AdminSessie[/COLOR][COLOR= #007700]]))
    {[/COLOR]
        
           [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Welkom op het beheerpaneel!<br /><br />Kies hieronder uit een van de mogelijkheden om iets op de website te plaatsen:[/COLOR][COLOR= #007700];
        
    }[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]U heeft niet de rechten om deze pagina te bekijken, u kunt <a href="login.php">hier</a> inloggen.[/COLOR][COLOR= #007700];
    }

}[/COLOR]
?>
0
Josnl

Lid · Topicstarter

Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bedankt voor de reacties allemaal, ik ga er even mee aan de slag!

EDIT:

Het is gelukt, heb het nu anders gedaan. (De if checkt nu of er wat in de SESSION staat)
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren