Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LOGIN.PHP
- _________________
- <?php
- session_start();
- error_reporting(0);
- if($_SESSION['logged_in']==true){
- header('Location: index.php?action=already_logged_in');
- }
- ?>
- <html>
- <head>
- <title>Login</title>
- <link type="text/css" rel="stylesheet" href="css/style.css" />
- </head>
- <body>
- <div id="loggain">
- <?php
- if($_GET['action']=='not_yet_logged_in'){
- echo "<div id='infoMesssage'>Du kan inte gå till index.php för att du är inte inloggad</div>";
- }
- if($_POST){
- $handle = fopen("!SÖKVÄG TILL TEXTFIL HÄR! t.ex. C:\\temp\\test.txt", "r");
- if ($handle) {
- $slackerEno = 0;
- $userArray;
- while (($line = fgets($handle)) !== false) {
- $userArray[i] = $line;
- slackerEno++;
- }
- fclose($handle);
- } else {
- // error opening the file.
- }
- $username = $userArray[0];
- $password = $userArray[1];
- if($_POST['username']==$username && $_POST['password']==$password){
- $_SESSION['logged_in'] = true;
- header('Location: index.php');
- }else{
- echo "<div>Fel användarnamn eller lösenord </div>";
- }
- }
- ?>
- <form action="login.php" method="post">
- <div id="formTitel">Login</div>
- <div id="form">
- <div >
- <input type="text" name="username" placeholder="Användarnamn" required autofocus />
- </div>
- <div >
- <input type="password" name="password" placeholder="Lösenord" required autofocus/>
- </div>
- <div>
- <input type="submit" value="Login" />
- </div>
- </div>
- <div>
- <a href="index.php">Gå till index </a>
- </div>
- </form>
- </div>
- </body>
- </html>
- INDEX.PHP
- _______________________________________
- <?php
- session_start();
- error_reporting(0);
- if(empty($_SESSION['logged_in'])){
- header('Location: login.php?action=not_yet_logged_in');
- }
- ?>
- <html>
- <head>
- <title>Inloggningen lyckades!</title>
- <link type="text/css" rel="stylesheet" href="css/style.css" />
- </head>
- <body>
- <?php
- $action = $_GET['action'];
- if($action=='logout'){
- session_destroy();
- header('Location: login.php');
- }
- else if($action=='already_logged_in'){
- echo "<div id='infoMesssage'>Du kan inte logga in, du är redan inloggad!</div>";
- }
- ?>
- <!-- some contents on our index page -->
- <div id='successMessage'>Du är inloggad :)</div>
- <div id='actions'>
- <a href='index.php?action=logout'>Logout?</a> | <a href='login.php'>Gå till loggin page</a>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement