Jump to content

problems with isset/session for a login form.


phingoc

Recommended Posts

Hi.

 

Link to project: www.smarttreff.moo.no

Login user: admin

login pw: 123

 

When i login the login form wont disapear. If i return to the index(Hjem) page without logging out, the loginform disapear. I am ussing session for the login

 

So the basicly, i want the loginform do disapear at once when the user has pushed login button(Logg in)

 

(dont laught at my "cut and past" for the include meny.. i just made the design and chopped it to bits and put it into includes):P

 

Index.php



<?php
session_start();

include("css.php");
include("header.php");
include("meny.php");
?>




    <td width="596" valign="top"><table width="100%" border="0" cellpadding="15">
      <tr>
        <td class="tabell" valign="top" align="left">
        
        
        Main
        
        
        </td>
      </tr>
    </table></td>
  </tr>
</table>

<?php
include("footer.php");
?>

 

meny.php

<table width="800" border="0">
  <tr>
    <td width="198" valign="top"><table width="100%" border="0" cellpadding="15">
      <tr>
        <td align="left" valign="top" class="tabell">
        <a href="index.php">Hjem</a>			<br />
        NÃ¥r og hvor	<br />
        For hvem		<br />
        
        SpørsmÃ¥l og svar<br />
        Forum			<br />
        <br />
        <br />
        Samarbeidspartnere
        </td>
      </tr>
    </table>
      <br />
      <table width="100%" border="0" cellpadding="15">
        <tr>
          <td class="tabell" valign="top" align="left">
<?php


if(isset($_SESSION['username']))
echo "Velkommen, " .$_SESSION['username']. "!<a href='innlogget.php'>Medlemsnyheter</a><br><a href='logout.php'>Log ut</a>";

else {
include("loginform.php");
}
?>
          </td>
        </tr>
      </table></td>
    <td width="15"> </td>

loginform.php

<form method="POST" action="login.php">

            <INPUT class="login" TYPE="TEXT" NAME="brukernavn" value="Brukernavn">

            <INPUT class="login" TYPE="PASSWORD" NAME="passord" value="Passord">

            <br><br>

            <INPUT class="button" TYPE="submit" value="Logg inn"> <input value="Registrere" class="button" Type="button" onClick="parent.location='login/registrer.php'">

    </form>

 

login.php (where session is created)

 

 

<?php

include("css.php");

include("header.php");

include("meny.php");

?>

 

 

 

 

    <td width="596" valign="top"><table width="100%" border="0" cellpadding="15">

      <tr>

        <td class="tabell" valign="top" align="left">

     

      <?php

 

session_start();

 

$username = $_POST['brukernavn'];

$password = $_POST['passord'];

 

IF ($username&&$password)

{

$connect = mysql_connect("localhost", "xxx", "xxx") or die("Kunne koble til database");

mysql_select_db("smarttreff") or die("Kunne ikke finne database");

 

$query = mysql_query("SELECT * FROM bruker WHERE brukernavn='$username'");

 

$numrows = mysql_num_rows($query);

 

if ($numrows!=0)

{

    while ($row = mysql_fetch_assoc($query))

    {

          $dbusername = $row['brukernavn'];

          $dbpassword = $row['passord'];

    }

    if ($username==$dbusername&&$password==$dbpassword)

    {

        echo "Du er nå logget inn. Vennligst klikk <a href='innlogget.php'>her</a> for å gå videre til brukersidene.";

 

        $_SESSION['username'] = $dbusername;

    }

    else

        echo "Feil passord";

}

else

    echo "Kunne ikke finne brukernavn";

 

 

 

}

else

    echo "Venligst tast inn ett brukernavn og passord";

 

?>

 

</td>

      </tr>

    </table></td>

  </tr>

</table>

 

<?php

include("footer.php");

?>

 


include("css.php");
include("header.php");
include("meny.php");
?>




    
      
        
      
      
session_start();

You can't have any output whatsoever, even spaces and blank lines, before calling session_start().

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.