duancaoqin6683 2014-02-17 01:49 采纳率: 0%
浏览 20

PHP cookie设置

I hate to say it but I have been working on what should have been a 30 minute assignment for a good 6 hours now with little to no progress. I am attempting to capture a name and email in a form, and set them to cookies that will last 10 minutes. While the cookies are active, the page should skip the form and just display the input. I have tried this with both cookies and sessions and cannot get it to work. At this point I have written and deleted at least a hundred lines of code and just can't really see what the problem is. This is my first time working with PHP. Any help would be appreciated. Currently this code creates the form, takes the info and posts it to the page correctly. When I go back to the page, it shows the form again. I assume this means the cookie isn't setting / sticking.

 if (!empty($_POST)) {
  setcookie('Cname',$_POST['name'], time()+600);
  setcookie('Cemail', $_POST['email'], time()+600);
//  header("Location:HW2.php");

<title> Assignment 2 Alcausin </title>


ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

$visibleForm = True;
    $visibleForm = False;
    $visibleForm = False;
    echo "Your Name: ";
    echo $_COOKIE['Cname'];
    echo "<br>";
    echo "Your Email: ";
    echo $_COOKIE['Cemail'];
if($visibleForm){ // close php if form is displayed
<form action ="HW2.php" method="post">
    Name:<font color = red>*</font> <input type="text" name="name"><br>
    E-mail:<font color = red>*</font> <input type="text" name="email"><br>
    <input type="submit" name="submit" value="Submit">
<?php   // back to php

  • 写回答

2条回答 默认 最新


      相关推荐 更多相似问题


      • ¥15 有关c++的问题,利用相关知识
      • ¥15 求香农编码和解码的matlab代码
      • ¥20 ROS中的TEB局部规划问题
      • ¥20 关于#matlab#的问题:要求测出上面图片中所有同心圆的半径
      • ¥20 epanet软件运行问题
      • ¥15 Python 文件读取
      • ¥60 dpabi进行Alff计算时脑池有干扰信号
      • ¥15 利用kmeans或kshape聚类分析对归一化的无量纲时间-降雨序列进行聚类
      • ¥15 protel99.SE提示一下弹窗
      • ¥15 银河麒麟v10 执行.run失败如何解决