首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >返回页面时显示已存在的"Fortune“

返回页面时显示已存在的"Fortune“
EN

Stack Overflow用户
提问于 2019-05-28 02:25:50
回答 2查看 59关注 0票数 0

一旦产生了财富,如果他们返回网站,就应该向他们展示他们从产生之日起下一年的现有财富。

如果用户想要创造新的财富,就给他们一个链接。

我的问题是,当我返回网站时,我不知道如何让它停留在生成的财富页面上,我试着搜索它,但没有找到任何东西。我想我已经做了一个重置链接,但我不确定。我需要什么样的代码才能让它留在财富页面上?

我在网上搜索了一下,我试着让它检查是否应用了cookie,但我们没有学到这一点。

主页(index.php)

代码语言:javascript
运行
复制
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Week 4 Tutorial - Fortune Teller</title>
</head>

<body>    
    <img src="fortune-teller.jpg" alt="The Fortune Teller" style="float:right;" />
    <h1>Fortune Teller</h1>
    <p>The fortune teller has looked deep in your soul, and has a sense of who you are and what will come in your life.</p>
    <p>What is your fate? How long will you live? Will you be successful or struggle in life? Find out below...</p>
    <form method="post" action="fortune.php">
        <label for="fname">First Name</label>
        <input type="text" id="fname" name="fname" />
        <br />
        <label for="colour">Favourite Colour</label>
        <input type="text" id="colour" name="colour" />
        <br />
        <label for="birthmonth">Birth Month</label>
        <select id="birthmonth" name="birthmonth">
            <option value="1">January</option>
            <option value="2">February</option>
            <option value="3">March</option>
            <option value="4">April</option>
            <option value="5">May</option>
            <option value="6">June</option>
            <option value="7">July</option>
            <option value="8">August</option>
            <option value="9">September</option>
            <option value="10">October</option>
            <option value="11">November</option>
            <option value="12">December</option>
        </select>
        <br />
        <input type="submit" id="submit" name="submit" value="Tell my fortune" />
    </form>
</body>
</html>

在您完成表单后的页面

代码语言:javascript
运行
复制
<?php
if(isset($_COOKIE['lastVisit']))
{
$visit = $_COOKIE['lastVisit'];
echo "Your last fortune was told at ". $visit;
}
//set to expire in a year
$year = +31556926 + time();
setcookie('lastVisit', date("G:i - m/d/y"), $year);
?>

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Week 4 Tutorial - Fortune Teller</title>
</head>

<body>    
    <img src="fortune-teller.jpg" alt="The Fortune Teller" style="float:right;" />
    <h1>Fortune Teller</h1>
    <p>The fortune teller has looked deep in your soul, and has a sense of who you are and what will come in your life.</p>
    <p>What is your fate? How long will you live? Will you be successful or struggle in life? Find out below...</p>

    <h2>Fortune for <?php echo $_POST['fname']; ?></h2>
    <p>
    <?php
        if($_POST['fname']=="Tony"){
                echo "You like to control everyone within your influence, to shape things to your own liking. ";
        }
        else if($_POST['fname']=="Ebonie"){
            echo "You're' fine when in harmony but changeable when in discord, because many of your best qualities are then reversed. ";
        }
        else if($_POST['fname']=="Eric"){
            echo "You have a vivid imagination who can bring inspired messages to the world. ";
        }
        else if($_POST['fname']=="Kristina"){
            echo "EXTREMES in fortune, health and spirituality. You are very versatile, idealistic and intuitive. ";
        }
        else if($_POST['fname']=="Jamie"){
            echo "You're' honest, benevolent, brilliant and often inventive, full of high inspirations. ";
        }else{
            echo "You're a decent person at best. ";
        }

        //Birthmonth - something to do with the season they were born in
        if($_POST['birthmonth']<4){
            //January, February, March - Q1 (Winter)
            echo "You are independent, analytic, and a born leader. ";
        }
        else if($_POST['birthmonth']<6){
            //April, May, June - Q2 (Spring)
            echo "You may be perceived as being stubborn, bossy, and impulsive. ";
        }
        else if($_POST['birthmonth']<9){
            //July, August, September - Q3 (Summer)
            echo "You are a sincere, candid, and sympathetic individual.. ";
        }
        else if($_POST['birthmonth']<12){
            //October, November, December - Q4 (Fall)
            echo "You are a practical philosopher who values a stable lifestyle. ";
        }

        //favourite colour - something about your job
        if($_POST['colour']=="red"){
            echo "You will find success in your career this month.";
        }
        else if($_POST['colour']=="blue"){
            echo "You need to be careful as you're on the verge of your employment being termenated.";
        }
        else if($_POST['colour']=="green"){
            echo "Show up to work early, keep your nose clean and your head down and you'll get a raise next month.";
        }
        else if($_POST['colour']=="yellow"){
            echo "A management position is in your future.";
        }
        else if($_POST['colour']=="black"){
            echo "Your difficulty working with others will cause tensions in the workplace in the near future.";
        }
        else{
            echo "Keep doing your job as well as you do now, good things will happen.";
        }
    ?>
    </p>
    <?php
      $url = htmlspecialchars($_SERVER['HTTP_REFERER']);
      echo "<a href='$url'>Reset</a>"; 
    ?>
</body>
</html>

预期的结果是,当你完成表单时,它将保存你最后一次到达页面的时间,显示我让它做的最后一次幸运的日期,但它还需要你在下次进入页面时留在该页面上,并使用一个重置按钮将你带回表单。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56330850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档