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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.