Jump to content

Dont understand whats wrong here


Xyphon

Recommended Posts

This is my top.php:

 

<?PHP

include('Connect.php');
$ID = $_COOKIE['UserID'];
$ID = mysql_real_escape_string($ID);
/* If logged out */
if (!isset($ID)) {
echo "
<html>
<title> Pokemon Trainer's Challenge RPG </title>
<center>
<head>
<style type='text/css'>

body 
{
background-color: lightgrey;
}
a:link { 
color: #000000;
}
a:visited { 
color: #000000;
}
font-color: black;
}
color: black;
}
.tables
{
border: 1px solid black;
</style>
</head>


<body>
<div align='center'>
<!--BANNER-->
<table class='tables' cellpadding='0' cellspacing='0' width='750px' border='3'>
<tr><td>
<center>
<a href='index.php'>
<img border='0' src='http://i7.tinypic.com/85xhu38.png'>
</font>
</tr></td>
</table>
<!--END of BANNER-->

<!--LEFT MENU-->
<table class='tables' cellpadding='0' cellspacing='0' width='750' border='3' table bgcolor='999999'>
<tr><td valign='top' width='150'>
<CENTER>
<b><font color='lightgrey' face='verdana' size='1'>Main</b><br>
<table cellpadding='0' cellspacing='0' width='980px'><tr>

<td class='nav_border' width='17%' valign='top'>
<b><font color='lightgrey' face='verdana' size='1'>General</b><br>
<a href='index.php'>Index</a></div>
<a href='login.php'>Login</a></div>
<a href='signup.php'>Sign Up</a></div><br />
</font>
</CENTER>
</td>
<!--END of LEFT MENU-->


<!--CONTENT-->
<td class='content' valign='top' width='750' bgcolor='#99999' border='3'>
<font size='1'>
<div align='justify'>
<br>
";
}
else
{
include("pokeinfo.php");
echo "
<html>
<title> Pokemon Trainer's Challenge RPG </title>

<head>
<style type='text/css'>

body 
{
background-color: lightgrey;
}
a:link { 
color: #000000;
}
a:visited { 
color: #000000;
}
font-color: black;
}
color: black;
}
.tables
{
border: 1px solid black;
</style>
</head>


<body>
<div align='center'>
<!--BANNER-->
<table class='tables' cellpadding='0' cellspacing='0' width='750' border='3'>
<tr><td width='1000px'>
<center>
<a href='index.php'>
<img border='0' src='http://i7.tinypic.com/85xhu38.png'>
</font>
</tr></td>
</table>
<!--END of BANNER-->
<!--LEFT MENU-->
<table class='tables' cellpadding='0' cellspacing='0' width='750' border='3' table bgcolor='999999'>
<tr><td width='200' valign='top'>
<CENTER>
<b><font color='lightgrey' face='verdana' size='1'>Main</b><br>
<a href='index.php'>Home</a><br>
<a href='logout.php'>Logout</a><br>
<a href='viewprofiles.php'>View A Profile</a><br>
<a href=''>Edit Your Profile</a><br>
<a href='members.php'>Member List</a><br>
<a href=''>Staff list</a><br><br>

<b>Others</b><br>
<a href='event.php'>Event</a><br>
<a href=''>Rules</a><br>
<a href=''>Forums</a><br>
<a href='storyadventure.php'>Story Adventure</a><br>
<a href=''>Buy and Sell Pokémon</a><br>
<a href=''>Trades</a><br><br>

<b>Explore</b><br>
<a href='map1.php'>Volcano Valley</a><br>
<a href='map2.php'>Icy Path</a><br>
<a href='map3.php'>Jirachi's Lair</a><br>
<a href='map4.php'>Thunder Plains</a><br>
<a href='map5.php'>Mystical Ocean</a><br>
<a href='map6.php'>Pokémon Fields</a><br><br>
<b>Battles</b><br>
<a href=''>Battle A Player</a><br>
<a href=''>Battle Gyms</a><br>
<a href=''>Battle Palace</a><br><br>
<b>Ranks</b><br>
<a href=''>Level Ranks</a><br>
<a href=''>Money Ranks</a><br><br>
</font>
</CENTER>
</td>
<!--END of LEFT MENU-->


<!--CONTENT-->
<td class='content' valign='top' width='800px' align='center' bgcolor='#99999' border='3'>
<font face='verdana' size='1'>
<div align='justify'>
<center>
<br>
";
$Resultpokemon= "SELECT * FROM pokemon_info WHERE user_id='$_COOKIE[userID]'";
if(mysql_num_rows(mysql_query($Resultpokemon)) == 0) {
echo "You haven't obtained your starter yet. Please obtain it now.<a href='obtainstarter.php'> Obtain Starter</a><br />";
}
}
$banned = array("70.104.67.150", "65.42.95.148", "82.153.135.161");
if (in_array($_SERVER['REMOTE_ADDR'], $banned)) 
{
echo "You have been IP banned.";
$usercheck = addslashes($_POST['username']);
    $passcheck = md5(addslashes($_POST['password']));
$Result1 = mysql_query("SELECT * FROM users WHERE username='$usercheck' AND password='$passcheck'");
    $Rows1 = mysql_fetch_array($Result1);
    

    $UserID = $Rows1['ID'];
$UserPosition = $Rows1['UserPosition'];
$UserName = $Rows1['UserName'];
setcookie("UserID", "$UserID", time() - 9999999);

setcookie("UserName", "$UserName", time() - 9999999);

setcookie("UserPosition", "$UserPosition", time() - 9999999);
include('bottom.php');
exit;
}

$BannedResult= mysql_query("SELECT * FROM users WHERE id='$ID'");
$BannedRows= mysql_fetch_array($BannedResult);

if($BannedRows['Banned']=='Yes')
{
echo "Sorry, you are banned. You will now be logged out, please go <a href='index.php'>back</a>.";
$usercheck = addslashes($_POST['username']);
$usercheck = mysql_real_escape_string($usercheck);
    $passcheck = md5(addslashes($_POST['password']));
$passcheck = mysql_real_escape_string($passcheck);
$Result1 = mysql_query("SELECT * FROM users WHERE username='$usercheck' AND password='$passcheck'");
    $Rows1 = mysql_fetch_array($Result1);
    

    $UserID = $Rows1['ID'];
setcookie("UserID", "$UserID", time() - 9999999);

include("bottom.php");
exit;
}
?>

 

Now the problem is. Even if $ID ($_COOKIE['UserID']; Isnt set, it will show it how it would when it is set. But if I try to do anything it'll say "Sorry, you are not logged in" So it isnt that it is being set or anything.

Link to comment
https://forums.phpfreaks.com/topic/130080-dont-understand-whats-wrong-here/
Share on other sites

change

 

include('Connect.php');
$ID = $_COOKIE['UserID'];
$ID = mysql_real_escape_string($ID);
if (!isset($ID)) {

 

to

 

include('Connect.php');
if (!isset($_COOKIE['UserID'])) {
$ID = $_COOKIE['UserID'];
$ID = mysql_real_escape_string($ID);

 

You're setting $ID to the cookie. Even if the cookie isn't set it still will set $ID, so isset($ID) will always return true...

As soon as you do

<?php
$ID = "something";
?>

it's being set.

 

I would reverse your code, so that the code for being logged in is first:

<?php

include('Connect.php');
if (isset($_COOKIE['UserID'])) {
$ID = mysql_real_escape_string($_COOKIE['UserID']);
include("pokeinfo.php");
echo "
<html>
<title> Pokemon Trainer's Challenge RPG </title>

<head>
<style type='text/css'>

body 
{
background-color: lightgrey;
}
a:link { 
	color: #000000;
	}
a:visited { 
	color: #000000;
	}
font-color: black;
}
color: black;
}
.tables
{
border: 1px solid black;
</style>
</head>


<body>
<div align='center'>
<!--BANNER-->
<table class='tables' cellpadding='0' cellspacing='0' width='750' border='3'>
<tr><td width='1000px'>
<center>
<a href='index.php'>
<img border='0' src='http://i7.tinypic.com/85xhu38.png'>
</font>
</tr></td>
</table>
<!--END of BANNER-->
<!--LEFT MENU-->
<table class='tables' cellpadding='0' cellspacing='0' width='750' border='3' table bgcolor='999999'>
<tr><td width='200' valign='top'>
<CENTER>
<b><font color='lightgrey' face='verdana' size='1'>Main</b><br>
<a href='index.php'>Home</a><br>
<a href='logout.php'>Logout</a><br>
<a href='viewprofiles.php'>View A Profile</a><br>
<a href=''>Edit Your Profile</a><br>
<a href='members.php'>Member List</a><br>
<a href=''>Staff list</a><br><br>

<b>Others</b><br>
<a href='event.php'>Event</a><br>
<a href=''>Rules</a><br>
<a href=''>Forums</a><br>
<a href='storyadventure.php'>Story Adventure</a><br>
<a href=''>Buy and Sell Pokémon</a><br>
<a href=''>Trades</a><br><br>

<b>Explore</b><br>
<a href='map1.php'>Volcano Valley</a><br>
<a href='map2.php'>Icy Path</a><br>
<a href='map3.php'>Jirachi's Lair</a><br>
<a href='map4.php'>Thunder Plains</a><br>
<a href='map5.php'>Mystical Ocean</a><br>
<a href='map6.php'>Pokémon Fields</a><br><br>
<b>Battles</b><br>
<a href=''>Battle A Player</a><br>
<a href=''>Battle Gyms</a><br>
<a href=''>Battle Palace</a><br><br>
<b>Ranks</b><br>
<a href=''>Level Ranks</a><br>
<a href=''>Money Ranks</a><br><br>
</font>
</CENTER>
</td>
<!--END of LEFT MENU-->


<!--CONTENT-->
<td class='content' valign='top' width='800px' align='center' bgcolor='#99999' border='3'>
<font face='verdana' size='1'>
<div align='justify'>
<center>
<br>
";
$Resultpokemon= "SELECT * FROM pokemon_info WHERE user_id='$_COOKIE[userID]'";
if(mysql_num_rows(mysql_query($Resultpokemon)) == 0) {
echo "You haven't obtained your starter yet. Please obtain it now.<a href='obtainstarter.php'> Obtain Starter</a><br />";
}
}
$banned = array("70.104.67.150", "65.42.95.148", "82.153.135.161");
if (in_array($_SERVER['REMOTE_ADDR'], $banned)) 
{
echo "You have been IP banned.";
$usercheck = addslashes($_POST['username']);
    $passcheck = md5(addslashes($_POST['password']));
$Result1 = mysql_query("SELECT * FROM users WHERE username='$usercheck' AND password='$passcheck'");
    $Rows1 = mysql_fetch_array($Result1);
    

    $UserID = $Rows1['ID'];
$UserPosition = $Rows1['UserPosition'];
$UserName = $Rows1['UserName'];
setcookie("UserID", "$UserID", time() - 9999999);

setcookie("UserName", "$UserName", time() - 9999999);

setcookie("UserPosition", "$UserPosition", time() - 9999999);
include('bottom.php');
exit;
}

$BannedResult= mysql_query("SELECT * FROM users WHERE id='$ID'");
$BannedRows= mysql_fetch_array($BannedResult);

if($BannedRows['Banned']=='Yes')
{
echo "Sorry, you are banned. You will now be logged out, please go <a href='index.php'>back</a>.";
$usercheck = addslashes($_POST['username']);
$usercheck = mysql_real_escape_string($usercheck);
    $passcheck = md5(addslashes($_POST['password']));
$passcheck = mysql_real_escape_string($passcheck);
$Result1 = mysql_query("SELECT * FROM users WHERE username='$usercheck' AND password='$passcheck'");
    $Rows1 = mysql_fetch_array($Result1);
    

    $UserID = $Rows1['ID'];
setcookie("UserID", "$UserID", time() - 9999999);

include("bottom.php");
exit;
} else {
/* If logged out */
echo "
<html>
<title> Pokemon Trainer's Challenge RPG </title>
<center>
<head>
<style type='text/css'>

body 
{
background-color: lightgrey;
}
a:link { 
	color: #000000;
	}
a:visited { 
	color: #000000;
	}
font-color: black;
}
color: black;
}
.tables
{
border: 1px solid black;
</style>
</head>


<body>
<div align='center'>
<!--BANNER-->
<table class='tables' cellpadding='0' cellspacing='0' width='750px' border='3'>
<tr><td>
<center>
<a href='index.php'>
<img border='0' src='http://i7.tinypic.com/85xhu38.png'>
</font>
</tr></td>
</table>
<!--END of BANNER-->

<!--LEFT MENU-->
<table class='tables' cellpadding='0' cellspacing='0' width='750' border='3' table bgcolor='999999'>
<tr><td valign='top' width='150'>
<CENTER>
<b><font color='lightgrey' face='verdana' size='1'>Main</b><br>
<table cellpadding='0' cellspacing='0' width='980px'><tr>

<td class='nav_border' width='17%' valign='top'>
<b><font color='lightgrey' face='verdana' size='1'>General</b><br>
<a href='index.php'>Index</a></div>
<a href='login.php'>Login</a></div>
<a href='signup.php'>Sign Up</a></div><br />
</font>
</CENTER>
</td>
<!--END of LEFT MENU-->


<!--CONTENT-->
<td class='content' valign='top' width='750' bgcolor='#99999' border='3'>
<font size='1'>
<div align='justify'>
<br>
";
}
?>

 

Ken

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.