Jump to content

Variable not setting o.O


timecatcher

Recommended Posts

Hey again, I am trying to set $_COOKIE['username'] as the variable $username however it doesn't appear to be working. The cookie is clearly correct as I can login fine, however when trying to echo out $username it just comes as '$username', heres the script that has the cookie stuff in:

 

<?php
session_start();
foreach ($_GET as $key => $value)
{
$$key = htmlentities ( $value );
}

foreach ($_SESSION as $key => $value)
{
$$key = htmlentities ( $value );
}

foreach ($_COOKIE as $key => $value)
{
$$key = htmlentities ( $value );
}

foreach ($_POST as $key => $value)
{
$$key = htmlentities ( $value );
}


echo<<<echo
<body bgcolor="#333333">
echo;

//Sets the $username variable for use in other scripts if the cookie exists.
if(isset($_COOKIE['username'])){
$username = $_COOKIE['username'];
}
//Checks if logged in to display page otherwise 'DIE'!
if($guest == false){
if(isset($_COOKIE['username'])){
}else{
$cke = "You need to be logged in to view this page.";
}
}
/*Checks if logged out otherwise 'DIE'! (Login, Register news ect.)*/
if($guest == true){
if(isset($_COOKIE['username'])){
$cke = "You are already logged in!";
//Cookie error.
}
}
//Checks the user against the rank and creates a function at the bottom.
if(isset($username)){
$rankquery = $db -> query("SELECT * FROM users WHERE username = %s AND rank = %s", $username, 5);
if(mysql_num_rows($rankquery) == 0){
$re = "You need to be an administrator to access this area.";
}
}


$openHTML = "<link rel='stylesheet' href='/layout/layoutstylesheet.css' type='text/css'><div id='banner'></div><div id='nav'>
<img src='/layout/block.png' width='157' height='250' usemap='#menu' alt='' border='0'/>
                <map name='menu'>
                        <area shape='poly' coords='0,2,154,3,155,21,1,21' href='$PHP_SELF' title='News' alt='News' />
					<area shape='poly' coords='1,35,150,35,150,55,1,55' href='$PHP_SELF' title='Adopt a Cyopet' alt='Adopt a Cyopet' />
					<area shape='poly' coords='1,70,150,70,150,90,1,90' href='$PHP_SELF' title='News' alt='News' />
					<area shape='poly' coords='1,105,150,105,150,125,1,125' href='$PHP_SELF' title='World' alt='World' />
					<area shape='poly' coords='1,140,150,140,150,160,1,160' href='$PHP_SELF' title='Visit the Plaza' alt='Visit the Plaza' />

					<area shape='poly' coords='1,180,150,180,150,200,1,200' href='$PHP_SELF' title='Orders' alt='Orders' />
                </map>
</div><div id='content'>";
//Open layout, this is the top bit, put this at the beginning of ANY scripts you have!
$closeHTML = "</div>";
//Goes at the end.


//Logged in already func.

function loggedin(){
global $cke;
global $openHTML;
global $closeHTML;
if(isset($cke)){
echo"$openHTML";
echo"$cke";
echo"$closeHTML";
die();
}
}

function rankadmin(){
global $re;
global $openHTML;
global $closeHTML;
if(isset($re)){
echo"$openHTML";
echo"$re";
echo"$closeHTML";
die();
}
}

?>

 

TC.

Link to comment
https://forums.phpfreaks.com/topic/147969-variable-not-setting-oo/
Share on other sites

I know that. The cookie is already set as im 'logged in' and I get the login message, but the $username variable im trying to store the cookie in isn't working when I echo it out, thus the message I get for the rank db query is that im not rank 5 which I am but it doesn't accept due to $username not existing seemingly.

 

TC.

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.