jd2007 Posted July 24, 2007 Share Posted July 24, 2007 <?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 Link to comment https://forums.phpfreaks.com/topic/61506-why-is-the-code-below-not-workingproblem-with-_sessionusername/ Share on other sites More sharing options...
metrostars Posted July 24, 2007 Share Posted July 24, 2007 session_start() at the top of every page that uses sessions, including pages where they are set/destroyed. Link to comment https://forums.phpfreaks.com/topic/61506-why-is-the-code-below-not-workingproblem-with-_sessionusername/#findComment-306145 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.