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 8893295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:12:36+00:00 2026-06-14T23:12:36+00:00

In PHP i will set the cookie and give it a value that’s a

  • 0

In PHP i will set the cookie and give it a value that’s a variable, when the user enters their name they will be taken to another page but when they get to that new page i need the value of that cookie changed to what name they entered, could someone show me how this would be done please?

  • 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-06-14T23:12:38+00:00Added an answer on June 14, 2026 at 11:12 pm

    in the first page (index.php) for example

    <?php
    //check if the form is submitted
    if($_POST['update_name']){
        if(!empty($_POST['name'])){
            //name filed is filled
    
            //define cookie expire time
            $expire = time()+60*60*24*30; #cookie will expire after a month
            //set the cookie
            setcookie("name", $_POST['name'], $expire);
            //take the user to another page
            header("location: page_two.php");
        }else{
        //form was submitted with empty name field
        //show error message
        echo "Name is required";
        }
    }
    ?>
    <form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
    <input type="text" name="name" />
    <input type="submit" name="update_name" value="Submit" />
    </form>
    

    in page_two.php

    <?php
    echo $_COOKIE["name"];
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to set up a cron job that will execute a php
I am using a PHP session manager class that will handle user sessions in
Many PHP systems will implement object types (such as Models) that allow a client
I am using a script in PHP that will allow me to send email,
I'm looking a symbol regex in PHP that will check submitted usernames and reject
Excerpt from http://php.about.com/od/advancedphp/ss/php_sessions.htm : So how will it know it's me? Most sessions set
I am implementing a php page counter that will keep track of each time
i'm trying to set cookie in a $.post request. My problem is that i
so i have this problem, i'm using a index.inc.php file to set a cookie
The empty() native in PHP will fail if the string is 0 or something

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.