Login issue

C++, C#, Java, PHP, ect...
Post Reply
Huezzer
Posts: 72
Joined: Mon Jan 31, 2011 7:47 pm

Login issue

Post by Huezzer »

hey,I've got a very annoying problem with my game, every time I press the login button the Authenticate page show up etc. but when that passed it send me back to "Not logged in.... click here for login page etc. But I can't figure out why it do that alll the time, Hope someone can help me..

Here's my Authenticate.php

Code: Select all

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

header('refresh: 2; url=index.php' );

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

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

Code: Select all

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

?>
  <link href="style.css" rel="stylesheet" type="text/css" />
<div id="login">

<form method="POST" action="authenticate.php">
User Name <input type="text" name="player" size="21">
Password <input type="text" name="password" size="21" mask="x">
<br>
<input type="submit" value="Login" name="submit">

<br><br>Not Registered? <a href='register.php'>Register
Forgot password? <A href="getpass.php">Get Password</a><br>
<br>
</form>
</div>
Game.php

Code: Select all

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

include_once 'logo.php';
?>
 <link href="style.css" rel="stylesheet" type="text/css" />
<div id="login2" div align="center">


<?php
if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}
?>
</div>
<?php
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
include_once 'statpanel.php';
 ?>
 <div id ="locations">
 <?php
$playersm = $playerinfo3['stamina'];
if ($playersm < 1)
{
  echo "You are dead!" ;
  echo "<br><a href='useitem.php>Use an Item";
  exit;
}

if(isset($_GET['map']))
{
$bypass=1;
echo "<a href='index.php?mapchange=1&mapname=Forbidden Forest'>Forbidden Forest";
echo "<br><a href='index.php?mapchange=1&mapname=Savannah'>The Savannah";
echo "<br><a href='index.php?mapchange=1&mapname=Deep Lake'>Deep Lake";
echo "<br><a href='index.php?mapchange=1&mapname=The Dark Cave'>The Dark Cave";
}

if(isset($_GET['mapchange']))
{
$bypass=1;
$mapname = $_GET['mapname'];
$name = $location['name'];
$level = $location['level'];
$price = $location['price'];
$gold = $price['gold'];

$updateplayer="update players set location='$mapname' where name='$playerinfo3[name]'";
  mysql_query($updateplayer) or die("Could not update player");

$updateplayer="update players set gold=gold-'$gold' where name='$player'";
if ($playerinfo3['level'] > $location['level'])
{
echo "<a>You are not high level enough to get to this Area!</a>";
echo "<a><center><a href='index.php'>Go Back</center></a>";
  }
  else
  {
  echo "You do not have enough gold for this trip!";
   echo "<center><a href='index.php'>Go Back</center>";
  exit;
}

echo "You have traveled to " . $mapname . ".<br>";
echo "<a href='index.php'>To location</a><br>";
}
if($bypass = 1)
{
echo "<b><big><u>" . $playerinfo3['location'] . "</u></big></b><br><br><br>";
echo "<a href='store.php'>Visit Store</a><br>";
echo "<a href='weaponshop.php'>Visit Weapon Shop</a><br>";
echo "<a href='armorshop.php'>Visit Armor Shop</a><br>";
echo "<a href='inn.php'>Visit Inn</a><br>";
echo "<a href='spelltrainer.php'>Visit Spell Trainer</a><br>";
echo "<a href='battle.php'>Battle in Arena</a><br>";
echo "<a href='game.php?map=1'>Go to Map</a><br>";
}

      print "<center><h3>Locations</h3></center>";
      print "<center>";
      print "<table border='0' width='70%' cellspacing='20'>";
      print "<tr><td width='25%' valign='top'>";
      print "</td>";
      print "<td valign='top' width='75%'>";
      $selectlocation="SELECT * from location";
      $selectlocation2=mysql_query($selectlocation) or die("could not select locations");
      print "<table border='1' bordercolor='black' bgcolor='#ffffff'>";
      print "<tr><td><font color='cc0033'>name:<font color='ffffff'>__________</td><td><font color='cc0033'>level<font color='ffffff'>__</font></td><td><font color='cc0033'>type<font color='ffffff'>____</font></td></tr>";
      while($selectlocation3=mysql_fetch_array($selectlocation2))
      {
       print "<tr><td>$selectlocation2[name]</td><td>$selectlocation2[level]</td><td>$selectlocation2[type]</td></tr>";    
      }
      print "</table>";
      print "</td></tr></table>";    
      print "</center>";
    
    
?>
</div>
<div id="logout">
<?php
echo "<br><a href='logout.php'><img src='images/logout.gif'></a>";
?>
</div>
Index.php

Code: Select all

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

include_once 'logo.php';
?>
 <link href="style.css" rel="stylesheet" type="text/css" />
<div id="login2" div align="center">


<?php
if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}
?>
</div>
<?php
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
include_once 'statpanel.php';
 ?>
 <div id ="locations">
 <?php
$playerhp = $playerinfo3['hpoints'];
if ($playerhp < 1)
{
  echo "You are dead!" ;
  echo "<br><a href='useitem.php>Use an Item";
  exit;
}

if(isset($_GET['map']))
{
$bypass=1;
echo "<a href='index.php?mapchange=1&mapname=Crocania'>Crocania</a><br>";
echo "<a href='index.php?mapchange=1&mapname=Fordale Woods'>Fordale Woods</a><br>";
echo "<a href='index.php?mapchange=1&mapname=Mintus Mountains'>Mintus Mountains</a><br>";
}

if(isset($_GET['mapchange']))
{
$bypass=1;
$mapname = $_GET['mapname'];

$updateplayer="update players set location='$mapname' where name='$playerinfo3[name]'";
  mysql_query($updateplayer) or die("Could not update player");
  
echo "You have traveled to " . $mapname . ".<br>";
echo "<a href='index.php'>To location</a><br>";
}

if($bypass != 1)
{
echo "<b><big><u>" . $playerinfo3['location'] . "</u></big></b><br>";
echo "<a href='store.php'>Visit Store</a><br>";
echo "<a href='weaponshop.php'>Visit Weapon Shop</a><br>";
echo "<a href='armorshop.php'>Visit Armor Shop</a><br>";
echo "<a href='inn.php'>Visit Inn</a><br>";
echo "<a href='spelltrainer.php'>Visit Spell Trainer</a><br>";
echo "<a href='battle.php'>Battle in Arena</a><br>";
echo "<a href='index.php?map=1'>Go to Map</a><br>";
}


 ?>
 </div>
<div id="logout">
<?php
echo "<br><a href='logout.php'><img src='images/logout.gif'></a>";
?>
</div>

Thanks, Huezzer :D
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Login issue

Post by Chris »

You're redirecting your page before making the session, this should work.

Code: Select all

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

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

$query = "SELECT name,password from members where name='$player' and password = '$password'";
$result = mysql_query($query) or die("Could not query players");
$result2 = mysql_fetch_array($result);
if ($result2)
{
$_SESSION['player']=$player;
header('refresh: 2; url=index.php' );
}
else
{
echo "<big>Wrong username or password.<A href='login.php'>Try Again</a></big>";
exit;
}
}
?>
Fighting for peace is declaring war on war. If you want peace be peaceful.
Huezzer
Posts: 72
Joined: Mon Jan 31, 2011 7:47 pm

Re: Login issue

Post by Huezzer »

Thanks for the code:

I've got one problem now, when I press Log in the Authenticate doesn't do anything, it's just a blank screen(White). it does go forward to the Authenticate page but not longer. just stands still.
Hope someone know whats the problem.

Authenticate.php

Code: Select all

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

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

$query = "SELECT name,password from members where name='$player' and password = '$password'";
$result = mysql_query($query) or die("Could not query players");
$result2 = mysql_fetch_array($result);
if ($result2)
{
$_SESSION['player']=$player;
header('refresh: 2; url=index.php' );
}
else
{
echo "<big>Wrong username or password.<A href='login.php'>Try Again</a></big>";
exit;
}
}
?>
Thanks, Huezzer
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: Login issue

Post by Torniquet »

you need to remove the 'url' from the header.

Code: Select all

header('refresh: 2; index.php'); 

EDIT~~

When i was doing this i got some errors appear, so what you may want to do in addition is put ob_start(); just after you start your session, the ob_end_flush(); after your header.
New Site Coming Soon! Stay tuned :D
Huezzer
Posts: 72
Joined: Mon Jan 31, 2011 7:47 pm

Re: Login issue

Post by Huezzer »

Still a blank page, doesn't go further, can someone help me?, 'cause I can't even log in to my game,

Here's the code:
Authenticate.php:

Code: Select all

<?php

include_once 'connect.php';
session_start();
ob_start();
if (isset($_POST['Login']))
{
$player=$_POST['player'];
$password=$_POST['password'];
$player=strip_tags($player);
$password=strip_tags($password);
$password=md5($password);

$query = "SELECT name,password from members where name='$player' and password = '$password'";
$result = mysql_query($query) or die("Could not query players");
$result2 = mysql_fetch_array($result);
if ($result2)
{
$_SESSION['player']=$player;
header ('refresh: 1; index.php'); 
ob_end_flush();
}
else
{
echo "<big>Wrong username or password.<A href='login.php'>Try Again</a></big>";
exit;
}
}
?>
Huezzer
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Login issue

Post by Chris »

Code: Select all

header('location: game.php'); 
Fighting for peace is declaring war on war. If you want peace be peaceful.
Post Reply

Return to “Coding”