Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I stand in the position where i have made a website locally to be used as a product to a later presentation.
The website within keeps login, address book, message center and events.
My problem is should in my login script (Since, tilslut.php) suddenly stopped working 100%. It works in the sense where i will be logged in from index.php, with the username "Nicolaj" with the password "123789456", but it keeps reporting invalid username / password when it must be approved from next page, check.php, after which it should be send to the page, forside.php

If you start to try to jump from check.php when it reported errors and on to forside.php there is no problem, but if you log out on the page forside.php. Then you can't access any of the other pages.

Someone who can help me with what it is that creates the problem? :)
(The codes for the various pages are listed below.)

Index.php
PHP
<?php
session_start();
$_SESSION['loggedin'] = true;
?>
<html>
<style type="text/css">@import url(css.css);</style>
<script>
function msg()
{
alert("Kontakt din administrator på Nicolaj-Aaroe@live.dk!");
}
</script>
<center><br><br><br><br>
<title>Familielogin:: LOGIN</title>
<font size="200" color="navy">Familieside</font><br>
Velkommen til familielogin<br>
Log venligst ind!

<form action="check.php" method="post" name="login">
B: <input type="text" value="username" name="username"/><br>
K: <input type="password" value="password" name="password"/><br>
<input type="submit" name="login" value="Log ind"/></form>
<input type="button" name="glemt" value="Glemt Login" onclick="msg()"/>
</form>
</div>
</html>


Check.php
PHP
<?php
$_SESSION['errors']=0;
$_SESSION['loggedin'] = true;
include("config.php");
?>
<?php

if(isset($_POST['login']));
{
$username=$_POST['username'];
$password=$_POST['password'];

$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM $tbl WHERE username='$username' and password='$password'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1)    {
$_SESSION['username'] = $_POST['username'];
header('Location: forside.php');
} else {
echo "<font color='red'><center><br><br><br><br>Forkert brugernavn eller password</font>";
} }
?>
<html>
<center><br><br><br><br>
<style type="text/css">@import url(css.css);</style>
<class id="body">
<script>
function goBack()
  {
  window.history.go(-1)
  }
</script>

<body>
<br><br><button onclick="goBack()">Gå tilbage og prøv igen</button>
</body>
</html>


Forside.php
PHP
<?php
session_start();
$_SESSION['loggedin'] = true;
if(isset($_SESSION['username'])) {
include('tilslut.php');
?>
<style type="text/css">@import url(css.css);</style>
<meta http-equiv="Content-Type" content="text/html;charset="UTF-8">
<table style="width:100%">
  <tr>
    <td width="50%"><font size="5" color="navy"><center>Familie Arrangementer<br><br></font></td>
    <td width="50%" align=right><font size="5" color="navy"><center>Meddelsescenter<br><br></font></td>
  </tr>
  <tr>
    <td><?php

$famarr = mysql_query("SELECT * FROM famarr ORDER by id DESC");

echo "<table width='100%' border='1' align='left' cellpadding='0' cellspacing='1' bgcolor='#FFFFFF'>
<tr>
<th>Navn</th>
<th>Sted</th>
<th>Dato</th>
</tr>";

while($row = mysql_fetch_array($famarr)) {
echo "<tr>";
  echo "<td>" . $row['navn'] . "</td>";
    echo "<td>" . $row['sted'] . "</td>";
      echo "<td>" . $row['dato'] . "</td>";
  echo "</tr>";
}

echo "</table>";

//mysql_close($con);
?></td>
    <td><?php
$result = mysql_query("SELECT * FROM beskeder ORDER by dato DESC");
while($row = mysql_fetch_array($result)) {
echo "<table width='100%' border='0' align='right' cellpadding='0' cellspacing='1' bgcolor='#CCCCCC'>
<tr>
<td><table width='100%' border='0' cellpadding='3' cellspacing='1' bgcolor='#FFFFFF'>
<tr>
<td>Dato</td>
<td>:</td>
<td>" . $row['dato'] . "</td>
</tr>
<tr>
<td width='50'>Navn</td>
<td width='14'>:</td>
<td width='357'>" . $row['navn'] . "</td>
</tr>
<td valign='top'>Besked</td>
<td valign='top'>:</td>
<td style='word-break:break-all;'>" . $row['besked'] . "</td>
</tr>
</table><br></td>
</tr>
</table>";

  echo "";
}

echo "";

?></td>
    <td></td>
  </tr>
<tr>
    <td><center><button onclick=window.location.href='famarr/fam.php'>Tilfoej arrangement</button></td>
    <td><center><button onclick=window.location.href='add/add.php'>Adressekarkotek</button> <button onclick=window.location.href='forum.php'>Skriv en besked</button> <button onclick=window.location.href='logud.php'>Log ud</button></table></td>
</tr>
</table>
<?php
} else {
?>
<center><h2><font color="navy"><br><br><br><br>Du er ikke logget ind, UPS!</font></h2></center>
<?php
}
?>


tilslut.php
PHP
<?php
$_SESSION['userName'] = '';

$host = "localhost";
$user = "root";
$pass = "";
$db = "famarr";

mysql_connect("$host", "$user", "$pass")or die("Kan ikke forbinde til databasen. :(");
mysql_select_db("$db")or die("Kan ikke finde databasen. :(");

error_reporting(E_ALL);
ini_set('display_errors', '1');
?> 
Posted
Comments
ChauhanAjay 22-Sep-14 21:23pm    
You are using a file config.php in check.php what does it contain?
Are config.php and tilslut.php the same i.e., both contain the same content?
Why haven't you included the session_start() in the check.php page?
Member 11101664 23-Sep-14 4:24am    
The config file is listed down below in the solution's

1 solution

Here's the config file:

PHP
<?php
$_SESSION['username'] = '';

define('host', 'localhost');
define('dbusername', 'Nicolaj');
define('dbpassword', '123789456');
define('db', 'famarr');
$tbl = "bruger";

mysql_connect("host", "dbusername", "dbpassword")or die("Kan ikke forbinde til databasen. :(");
mysql_select_db("db")or die("Kan ikke finde databasen. :(");
 
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>


There is already a session start in the config file, therefor i haven't included one in the check.php file
 
Share this answer
 
v4
Comments
ChauhanAjay 23-Sep-14 14:01pm    
Can you echo your select query in the variable $sql in check.php if all the values are correct or not?
for example you have used a variable $tbl is it being replaced with the value "bruger" or not.
Member 11101664 23-Sep-14 15:26pm    
What do you mean? could you maybe try to type what you mean i need to try, in the codes so i can paste it in my file and see if it works?
ChauhanAjay 23-Sep-14 17:53pm    
echo $sql; // add this line to your code below your sql query in check.php And let me know the result

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900