Browser MMO Video #5

Location of the Videos
Feuerqueen
Posts: 7
Joined: Fri Jan 14, 2011 8:47 pm

Re: Video#5

Post 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!
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: Video#5

Post 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.
Feuerqueen
Posts: 7
Joined: Fri Jan 14, 2011 8:47 pm

Re: Video#5

Post 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.
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: Video#5

Post 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.
NDest
Posts: 11
Joined: Tue Feb 01, 2011 12:43 pm

Re: Video#5

Post 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>";
   }
}
?>
NDest.
Onwer of
Image
a minecaft server
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video#5

Post by hallsofvallhalla »

show us your login.php..sounds like a form problem
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: Video#5

Post 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.
NDest
Posts: 11
Joined: Tue Feb 01, 2011 12:43 pm

Re: Video#5

Post 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
NDest.
Onwer of
Image
a minecaft server
alexander19
Posts: 180
Joined: Fri Apr 02, 2010 1:05 pm

Re: Video#5

Post 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.
NDest
Posts: 11
Joined: Tue Feb 01, 2011 12:43 pm

Re: Video#5

Post 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
NDest.
Onwer of
Image
a minecaft server
Post Reply

Return to “Older Browser MMO Videos”