Jump to content

Why is the code below not working...problem with $_SESSION['username'] ?


jd2007

Recommended Posts

<?php
$id=$_GET["id"];
//check if user is logged in or not
if (!$_SESSION["username"])
{
$theIP=$_SERVER['REMOTE_ADDR'];
include("connect.php");
$query="SELECT userip FROM dip WHERE userip='$theIP'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if ($num>0)
{
  $already="You have already used your 1 free rom credit, feel free to register and visit the faq on how to receive more.";
  header("location:index.php?d=$already");
}
else
{
  $query2="SELECT link FROM games WHERE id=$id";
  $result2=mysql_query($query2);
  $row=mysql_fetch_row($result2);
  if ($row)
  {
   $query3="insert into dip (gameid, userip) values ('$id','$theIP')";
   $result3=mysql_query($query3);
   header("location:$row[0]");
  }
  else
  {
   $not="Game could not be found.";
   header("location:index.php?not=$not");
  }
}
}
else
{
include("connect.php");
$query="SELECT credits FROM users WHERE username='$_SESSION[username]'";
$result=mysql_query($query);
$row=mysql_fetch_row($result);
if ($row[0]>0)
  {
   $query3="SELECT link FROM games WHERE id=$id";
   $result3=mysql_query($query3);
   $num3=mysql_num_rows($result3);
   if ($num3>0)
   {
   $query2="update table games set credits=credits-1 where username=$_SESSION[username]";
   $result2=mysql_query($query2);
   header("location:$row[0]");
   }
   else
   {
    $not="Game could not be found.";
    header("location:index.php?not=$not");
   }
  }
else 
  {
   $no="You have no more credits left. Read the <a href='faq.php'>FAQ</a>.";
   header("location:index.php?no=$no");
  }
  
}


?>



 

the code :

 

if (!$_SESSION["username"])

 

checks if user is logged in...if not it'll do :

 

 $theIP=$_SERVER['REMOTE_ADDR'];
include("connect.php");
$query="SELECT userip FROM dip WHERE userip='$theIP'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if ($num>0)
{
  $already="You have already used your 1 free rom credit, feel free to register and visit the faq on how to receive more.";
  header("location:index.php?d=$already");
}
else
{
  $query2="SELECT link FROM games WHERE id=$id";
  $result2=mysql_query($query2);
  $row=mysql_fetch_row($result2);
  if ($row)
  {
   $query3="insert into dip (gameid, userip) values ('$id','$theIP')";
   $result3=mysql_query($query3);
   header("location:$row[0]");
  }
  else
  {
   $not="Game could not be found.";
   header("location:index.php?not=$not");
  }
}

 

if logged in, it will do this:

 

$theIP=$_SERVER['REMOTE_ADDR'];
include("connect.php");
$query="SELECT userip FROM dip WHERE userip='$theIP'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if ($num>0)
{
  $already="You have already used your 1 free rom credit, feel free to register and visit the faq on how to receive more.";
  header("location:index.php?d=$already");
}
else
{
  $query2="SELECT link FROM games WHERE id=$id";
  $result2=mysql_query($query2);
  $row=mysql_fetch_row($result2);
  if ($row)
  {
   $query3="insert into dip (gameid, userip) values ('$id','$theIP')";
   $result3=mysql_query($query3);
   header("location:$row[0]");
  }
  else
  {
   $not="Game could not be found.";
   header("location:index.php?not=$not");
  }
}

 

my problem is eventhough user is logged in, it still does this:

 

$theIP=$_SERVER['REMOTE_ADDR'];
include("connect.php");
$query="SELECT userip FROM dip WHERE userip='$theIP'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if ($num>0)
{
  $already="You have already used your 1 free rom credit, feel free to register and visit the faq on how to receive more.";
  header("location:index.php?d=$already");
}
else
{
  $query2="SELECT link FROM games WHERE id=$id";
  $result2=mysql_query($query2);
  $row=mysql_fetch_row($result2);
  if ($row)
  {
   $query3="insert into dip (gameid, userip) values ('$id','$theIP')";
   $result3=mysql_query($query3);
   header("location:$row[0]");
  }
  else
  {
   $not="Game could not be found.";
   header("location:index.php?not=$not");
  }
}

 

why ? pls help

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.