Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6068535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:43:31+00:00 2026-05-23T09:43:31+00:00

what do I set the cookie value and name to be for a value

  • 0

what do I set the cookie value and name to be for a value a user may enter in a form? and what do i use to display that value on my second page? (I can’t not use cookies for this, so while there may be a smarter way to do this, I would just like to know how to do it with cookies!!) Thanks!

<?php
setcookie($color, 'color');
setcookie($name, 'name');
?>

<?php
echo "<form action=\"form_data.php\" method=\"post\">";
echo "favorite color:<input type=\"text\" name=\"color\" size=\"20\"><br/>";
echo "name:<input type=\"text\" name=\"name\" size=\"20\"><br/>";
echo "<input type=\"submit\" value=\"Submit\" />";
echo "<br /><input type=\"hidden\" name=\"submitted\" value=\"true\" />";
?>

data on form_data:

  <?php
  echo "<b>fav color:</b>".$_COOKIE['color'];
  echo "<b>name:</b>".$_COOKIE['name'];
  ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:43:32+00:00Added an answer on May 23, 2026 at 9:43 am

    First, you have your form:

    <?php
    echo "<form action=\"form_data.php\" method=\"post\">";
    echo "favorite color:<input type=\"text\" name=\"color\" size=\"20\"><br/>";
    echo "name:<input type=\"text\" name=\"name\" size=\"20\"><br/>";
    echo "<input type=\"submit\" value=\"Submit\" />";
    echo "<br /><input type=\"hidden\" name=\"submitted\" value=\"true\" />";
    ?>
    

    Then in form_data.php:

    <?php
    // set the cookie with the submitted user data
    setcookie('color',$_POST['color']);
    setcookie('name', $_POST['name']);
    echo "<b>fav color:</b>".$_COOKIE['color'];
    echo "<b>name:</b>".$_COOKIE['name'];
    ?>
    

    However, you’ll notice that the $_COOKIE variables are not available yet… if you reload that page, they will appear.

    In order to accomodate this behavior of cookies, you can setup a redirect in form_data.php:

    <?php 
     if (!empty($_POST)) {
      // set the cookie with the submitted user data
      setcookie('color',$_POST['color']);
      setcookie('name', $_POST['name']);
      // redirect the user to final landing page so cookie info is available
      header("Location:form_data.php");
     } else {
      echo "<b>fav color:</b>".$_COOKIE['color'];
      echo "<b>name:</b>".$_COOKIE['name'];
     }
    ?>
    

    You can redirect them anywhere suitable. Hope this helps and good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cookie set as yab_uploadmode and it has numeric value ranging from
I'd like to set a cookie via Django with that has several different values
I am trying to set a cookie in my Google App Engine page: self.response.headers.add_header('Set-Cookie','CookieName=1234;
I am using urllib2 to interact with a website that sends back multiple Set-Cookie
there is one think, i can't understand anyway:((( when i try to set cookie(it
Is it possible to set a cookie in an iPhone Application that persists, so
(Note: See also the related question Can browsers react to Set-Cookie specified in headers
I'm trying to see if I can set a cookie during the Application_Error() event
Essentially I'm trying to set a cookie after a user logs in to persist
is not work for some cookie #!/usr/bin/perl -w use strict; use warnings; use LWP::UserAgent;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.