After a series of tests I found this
When I use
<?php
$test = "TRE";
setcookie('username',$test,time()+3600);
?>
It creates cookie and showsup in my cookie files
When I use
<?php
echo $_COOKIE['username'];
?>
It prints the value of username... IT WORKS!!! BUT
When I use
<?php
$message = NULL;
if(isset($POST['submit']))
{
$username=$POST['username'];
$password=$POST['password'];
$userip = $SERVER['REMOTE_ADDR'];
if(strlen(trim($username)) < 3)
{
$message = "<p class=\"error\">Error: Nick name should be atleast 3 characters</p>";
}
else
{
if((strcmp(strtoupper(trim($username)),"NANDA") == 0 || strcmp(strtoupper(trim($username)),"NANDA KISHORE") == 0 || strcmp(strtoupper(trim($username)),"WEBMASTER") == 0 || strcmp(strtoupper(trim($username)),"BOBBY") == 0 || strcmp(strtoupper(trim($username)),"BOB") == 0) && strcmp(trim($password),"xxxxxx") != 0)
{
$message = "<p class=\"error\">Error: You chose an Admnistrator nick, please choose another nick name</p>";
}
else
{
$db = @mysql_connect('localhost','','') or die('Error Connecting My DB Server Plz try later');
@mysql_select_db('mychat') ; $query = "INSERT INTO users(user_name,user_ip) VALUES('$username','$userip')";
$result = @mysql_query($query) or die("Error: unknown eMail [email]nanda@wayne.edu[/email]");
mysql_close();
[COLOR=red]setcookie('username',$username);[/COLOR]
}
}
}
?>
And use the same read file as above
<?php
echo $_COOKIE['username'];
?>
IT GIVES AN ERROR
Notice: Undefined index: username in c:\inetpub\wwwroot\page\mychat\test2.php on line 2
Now if I execute the read code in same window it works.. but If I close the browser and open a new window it doesnt work and gives the above error. Also the cookie which is set with the first code is erased. Its bizarre.
BTW Sorry for spaming with the whole code.