phingoc Posted October 3, 2011 Share Posted October 3, 2011 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) 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> Link to comment https://forums.phpfreaks.com/topic/248353-problems-with-issetsession-for-a-login-form/ Share on other sites More sharing options...
requinix Posted October 3, 2011 Share Posted October 3, 2011 All those leading spaces have to go. You can't have any output whatsoever, even spaces and blank lines, before calling session_start(). Link to comment https://forums.phpfreaks.com/topic/248353-problems-with-issetsession-for-a-login-form/#findComment-1275362 Share on other sites More sharing options...
phingoc Posted October 3, 2011 Author Share Posted October 3, 2011 <?php All those leading spaces have to go. You can't have any output whatsoever, even spaces and blank lines, before calling session_start(). Removed the empty lines, but no luck. Link to comment https://forums.phpfreaks.com/topic/248353-problems-with-issetsession-for-a-login-form/#findComment-1275364 Share on other sites More sharing options...
requinix Posted October 3, 2011 Share Posted October 3, 2011 Wait... Where are you setting $_SESSION["username"]? loginform.php? What's the code for that? Link to comment https://forums.phpfreaks.com/topic/248353-problems-with-issetsession-for-a-login-form/#findComment-1275375 Share on other sites More sharing options...
phingoc Posted October 4, 2011 Author Share Posted October 4, 2011 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"); ?> Link to comment https://forums.phpfreaks.com/topic/248353-problems-with-issetsession-for-a-login-form/#findComment-1275643 Share on other sites More sharing options...
requinix Posted October 4, 2011 Share Posted October 4, 2011 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(). Link to comment https://forums.phpfreaks.com/topic/248353-problems-with-issetsession-for-a-login-form/#findComment-1275674 Share on other sites More sharing options...
phingoc Posted October 4, 2011 Author Share Posted October 4, 2011 Thank you. Removed all empty lines before session_start(); and additional moved "session_start();" from the script to line 2. Thank you so much! Link to comment https://forums.phpfreaks.com/topic/248353-problems-with-issetsession-for-a-login-form/#findComment-1275690 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.