Jump to content

Cookie issue while accessing on another page


Pawan_Agarwal
Go to solution Solved by 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 ???
 
 
 
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.