Page 24 of 35

Re: Video#5

Posted: Fri Jan 14, 2011 9:00 pm
by Feuerqueen
I really love your tutorials :)
I haven't had much knowledge about php before but I managed to set up a registration and a login, but the login doesn't work.
I get this error message:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\MDR\lay\index.php:18) in C:\xampp\htdocs\MDR\lay\includes\authenticate.inc.php on line 2
Logged in successfully
Continue

Here my codes

Login

Code: Select all

<form method="POST" action="index.php?site=authenticate">
Nickname: <input type="text" name="name" size="21"><br>
Passwort: <input type="password" name="password" size="21">
<br>
<input type="submit" value="Login" name="submit">
authenticate

Code: Select all

<?php
session_start();
include_once 'connect.php';

if (isset($_POST['submit']))
{
  $name=$_POST['name'];
  $password=$_POST['password'];
  $name=strip_tags($name);
  $password=strip_tags($password);
  $password=md5($password);

  $query = "select name,password from user where name='$name' and password='$password'";
  $result = mysql_query($query) or die("Could not query players");
  $result2 = mysql_fetch_array($result);
  if ($result2)
  {
    $_SESSION['name']=$name;
   
    echo "<big>Logged in successfully<br>";
    echo "<A href='index.php?site=startseite'>Continue</a></big>";
  }
  else
  {
   echo "<big>Wrong username or password.<A href='index.php?site=login'>Try Again</a></big>";
  }
}
?>
The problem is that I use a layout where I have to change the links. Maybe this is why it doesn't work? Because it loggs me in sucessfully but there also is a error message. In my code "player" is named "name" and my database is "user".
I hope someone can help me. I just can't figure out were I went wrong.

Thank you very much!

Re: Video#5

Posted: Fri Jan 14, 2011 9:30 pm
by PaxBritannia
Welcome to the forums, Feuerqueen. Congratulations on your first post.

To get rid of headers already sent error add

Code: Select all

<?php ob_start(); ?>
to the first line of your script.

Lets see if that works.

Pax.

Re: Video#5

Posted: Fri Jan 14, 2011 9:58 pm
by Feuerqueen
Thank you very much!

But what does the ob_start code do? is it the same or nearly the same like session_start? And do I have to use session_start, too? because the error message just removes when i delete the session_start, but not when i only add the ob_start in front. I just doesn't know if it will work the same without the session_start.

Re: Video#5

Posted: Fri Jan 14, 2011 10:13 pm
by PaxBritannia
ob_start buffers your headers.

That is, your code's output is stored in your XAMP stack (the server) and only sent when the script finishes. If it detects and headers, it will send those immediately so the headers already sent error will not occur.

Without session start, the tutorial script will not work unless you change some parts of it. Anything that uses the session superglobal array i.e.($_SESSION['Variable']) will not work. In larger sites, you shouldn't actually use sessions. Instead use an identifier cookie to call the database.

I'll upload a cookie tutorial soon, so you'll know how to change it if you decide to.

pax.

Re: Video#5

Posted: Tue Feb 01, 2011 12:48 pm
by NDest
Hi i really love this tutorials but dunno why, when i click login nothing appears in authenticate,

I did everything like hall but still doesnt work:

here's my code (EDIT: I typed, didnt copied)

Code: Select all

<?php
include_once 'connect.php';
session_start();

if (isset($_POST['submit']))
{
   $player=$_POST['player'];
   $password=$_POST['password'];
   $player=strip_tags($player);
   $password=strip_tags($password);
   $password=md5($password);

   $query = "Select name,password from players where name= '$player' and '$password' ";
   $result = mysql_query($query) or die("Could not query  players");
   $result2 = mysql_fetch_array($result);
   if ($result2)
   {
   $_SESSION['player']=$player;
   echo "<big>Logged in successfully<br>";
   echo "<A href='battle.php'>Continue</a></big>";
   }
   else
   {
   echo "<big> Wrong username or password.<A href='login.php'>Try Again</a></big>";
   }
}
?>

Re: Video#5

Posted: Wed Feb 02, 2011 12:52 am
by hallsofvallhalla
show us your login.php..sounds like a form problem

Re: Video#5

Posted: Wed Feb 02, 2011 6:03 am
by PaxBritannia
Hi NDest!

Welcome to indie-resource! :D

As Halls has mentioned, the showing us the code for the page with the form would really help solve this.

pax.

Re: Video#5

Posted: Fri Feb 04, 2011 12:37 pm
by NDest
Heres my Login Code:

Code: Select all

<form method="POST" action="authenticate.php">
User Name <input type="text" name"player" size="21"><br>
Password <input type="password" name="password" size="21">
<br>
<input type="submit" value="Login" name"submit">
Whats strange is that, i had some errors on Authenticate first and i repaired them, after that it appears like i said before a Blank Page
EDIT: its like it doesnt even run it , but it goes to the link

Thanks, best regards,
NDest

Re: Video#5

Posted: Fri Feb 04, 2011 9:52 pm
by alexander19
In your authenticate.php script change:

Code: Select all

   $query = "Select name,password from players where name= '$player' and '$password' ";
to

Code: Select all

   $query = "Select name,password from players where name= '$player' and  password='$password' ";
And on your login page you forgot to add an "=" near your player value:

Code: Select all

User Name <input type="text" name"player" size="21"><br>
should be:

Code: Select all

User Name <input type="text" name="player" size="21"><br>
Hope that helps.

Re: Video#5

Posted: Fri Feb 04, 2011 11:07 pm
by NDest
Thanks a lot, but i just noticed a while ago and went to the forum :P

Still thanks,

Its Great to have a cool Forums that help a lot

Best Regards,
NDest