duanang58939 2017-01-31 03:04
浏览 53

如果没有选择任何内容,PHP setcookie不显示

So what i want to make and what i have problems with!

  1. The "all" is not showing if the user haven't selected a currency!

  2. How to write the code so if the "all" is loaded it uses the code from the individual if's per currency

  3. How to delete the the use of <input type="submit" value="Select currency"> button so its automatic change when a Currency is selected

(inside the <body>)

So how to delete the use of <input type="submit" value="Select currency"> button so its automatic change when a Currency is selected?

<form action="currency_switcher.php" method="post">
    <select name="money">
        <option value="all"<?php if( $_COOKIE["currency"] == "all" ) { echo " selected"; } ?>>All Currencies</option>
        <option value="IDR"<?php if( $_COOKIE["currency"] == "IDR" ) { echo " selected"; } ?>>Indonesia RP</option>
        <option value="AUD"<?php if( $_COOKIE["currency"] == "AUD" ) { echo " selected"; } ?>>Australian Dollars</option>
        <option value="USD"<?php if( $_COOKIE["currency"] == "USD" ) { echo " selected"; } ?>>American Dollars</option>
        <option value="SGD"<?php if( $_COOKIE["currency"] == "SGD" ) { echo " selected"; } ?>>Singapore Dollars</option>
    </select>
<input type="submit" value="Select currency">
</form>

So the "all" is not showing if the user haven't selected a currency!

And how to write the code so the code from example IDR showing if ALL currency is loaded so i dont need to have the code two times written!.

<?php

    if( $_COOKIE["currency"] == "all") {

    echo "code";
    echo "code IDR";
    echo "code";
    echo "code AUD";
    echo "code";
    echo "code USD";
    echo "code";
    echo "code SGD";
    }


    if ( $_COOKIE["currency"] == "IDR" ) {

    echo "code IDR";
    }

    if ( $_COOKIE["currency"] == "AUD" ) {

    echo "code AUD";
    }

    if ( $_COOKIE["currency"] == "USD" ) {

    echo "code USD";
    }

    if ( $_COOKIE["currency"] == "SGD" ) {

    echo "code SGD";
    }

    ?>

The currency_switcher.php

<?
$money = "all";
if( isset( $_POST["money"] ) ) {
    $money = $_POST["money"];
    setcookie ( 'currency', $money, time() + 60*60*24*30, '/', 'exampledomain.com');
    header('Location: ' . $_SERVER['HTTP_REFERER']);
    exit;
}
?>

</div>
  • 写回答

1条回答 默认 最新

  • dongtiao0657 2017-01-31 03:08
    关注

    Setting the cookie example:

    $first_name = 'David'; setcookie('first_name',$first_name,time() + (86400 * 7)); // 86400 = 1 day
    

    Getting the cookie:

    echo 'Hello '.($_COOKIE['first_name']!='' ? $_COOKIE['first_name'] : 'Guest'); // Hello David!
    

    Or set the cookie with more specific directives, for example:

    setcookie('first_name',$first_name,time() + (86400* 7),'/~sugar/','davidwalsh.name',true,true);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 vscode的问题提问
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM