Jump to content

Cookie issue while accessing on another page


Pawan_Agarwal

Recommended Posts

I am trying to access the values from "first.php" page to "visit.php", I am able to get the values , however, while creating and destroying cookies, I am facing error. 

 

----------------FIRST.PHP----------------

 

<?php
error_reporting(E_ALL);
 
if(isset($_COOKIE["_user_name"])){
setcookie("_user_name", "", time()-(3600*1000));
echo $_COOKIE["_user_name"];
}
?>
 
<form method='post' action="visit.php">
<input type="text" name="name1"/>
<input type="submit" value="Submit"/>
</form>
----------------FIRST.PHP----------------
 
----------------VISIT.PHP----------------
<?php
error_reporting(E_ALL);
if(isset($_POST["name1"]))
{
$name = $_REQUEST["name1"];
echo "Value = ".$name;
setcookie("_user_name", $name, time()+3600); 
}
?>
----------------VISIT.PHP----------------
 
When I enter name on "FIRST.PHP",  I am able to access it on "VISIT.PHP", but I am facing waring
 
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\counter\visit.php:6) in C:\xampp\htdocs\counter\visit.php on line 7
 
I am deleting the existing cookie on "FIRST.PHP" and then accessing value from "FIRST.PHP" to "VISIT.PHP",
 
I am trying to create cookie on "VISIT.PHP".....
 
Can you help me in getting the warning removed ???
 
 
 

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.