0

我想知道是否有人能发现我的 php 代码有什么问题,用于设置 cookie。谢谢!

    $expire=time()+60*60*24*30;
    $selected_image = $_GET["img"];
    $selected_caption = $_GET["caption"];
    $selected_color = $_GET["color"];

    switch ($selected_image){
        case:"img1"
            setcookie("img1_caption", $selected_caption, $expire);
            setcookie("img1_color", $selected_color, $expire);
            break;
        case:"img2"
            setcookie("img2_caption", $selected_caption, $expire);
            setcookie("img2_color", $selected_color, $expire);
            break;
        case:"img3"
            setcookie("img3_caption", $selected_caption, $expire);
            setcookie("img3_color", $selected_color, $expire);      
            break;
        case:"img4"
            setcookie("img4_caption", $selected_caption, $expire);
            setcookie("img4_color", $selected_color, $expire);          
            break;
    }
4

1 回答 1

2

你的语法不正确。:追求价值。请参阅文档

switch ($selected_image){
    case "img1":
        setcookie("img1_caption", $selected_caption, $expire);
        setcookie("img1_color", $selected_color, $expire);
        break;
    case "img2":
        setcookie("img2_caption", $selected_caption, $expire);
        setcookie("img2_color", $selected_color, $expire);
        break;
    case "img3":
        setcookie("img3_caption", $selected_caption, $expire);
        setcookie("img3_color", $selected_color, $expire);      
        break;
    case "img4":
        setcookie("img4_caption", $selected_caption, $expire);
        setcookie("img4_color", $selected_color, $expire);          
        break;
}
于 2013-01-27T20:06:07.010 回答