从cookie的信息PHP数组:只显示您刷新页面后? [英] PHP array from cookie info: only shows up after you refresh the page?

查看:132
本文介绍了从cookie的信息PHP数组:只显示您刷新页面后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想从该公司做出来的饼干用户输入信息的数组的形式返回的项目,它工作正常,除了当你第一次从previous页面访问该页面,没有显示出来,而你要刷新它实际看到的阵列。我不知道为什么它会绕不露面的第一次? (里面还有一些JavaScript警告说做工精细这只是我遇到的麻烦的阵列。)这是我的code,任何意见将是巨大的,谢谢

  $ usergatsby = $ _COOKIE ['gatq'];
$ usercatcher = $ _COOKIE ['catcherq'];
$ userwaves = $ _COOKIE ['wavesq'];
$ userstranger = $ _COOKIE ['strangerq'];
$ userulysses = $ _COOKIE ['ulyssesq'];
$ userpride = $ _COOKIE ['prideq'];
$ usermockingbird = $ _COOKIE ['mockingbirdq'];
$ userroad = $ _COOKIE ['roadq'];
如果($ _COOKIE ['FNAME'] == NULL或$ _COOKIE ['LNAME'] == NULL或$ _COOKIE ['地址'] == NULL或$ _COOKIE ['城市'] == NULL或$ _COOKIE ['国家] == NULL或$ _COOKIE ['拉链'] == NULL或$ _COOKIE [电子邮件] == NULL)
{回声< SCRIPT LANGUAGE =JavaScript的'>
window.alert(你离开了个人信息页面的信息,您将被重定向!');
    window.location.href ='personal.php';&下; /脚本>中;
}其他
    {
    如果($ _COOKIE ['gatq'] == NULL和放大器;&安培;
        $ _COOKIE ['catcherq'] == NULL和放大器;&安培;
        $ _COOKIE ['wavesq'] == NULL和放大器;&安培;
        $ _COOKIE ['strangerq'] == NULL和放大器;&安培;
        $ _COOKIE ['ulyssesq'] == NULL和放大器;&安培;
        $ _COOKIE ['prideq'] == NULL和放大器;&安培;
        $ _COOKIE ['mockingbirdq'] == NULL和放大器;&安培;
        $ _COOKIE ['roadq'] == NULL)            {回声< SCRIPT LANGUAGE =JavaScript的'>
                window.alert('您没有在您的购物车什么,你将被重定向!');
                window.location.href ='inventory.php';&下; /脚本>中;
            }                    其他
                        {$ productarray =阵列($ usergatsby =>了不起的盖茨比< IMG SRC =gatsby.jpg>,
             $ usercatcher =>麦田里的守望者< IMG SRC =catcher.jpg>,
              $ userwaves = GT;'海浪&下; IMG SRC =waves.jpg>',
              $ userstranger =>陌生人< IMG SRC =stranger.jpg>,
              $ userulysses = GT;'尤里西斯&下; IMG SRC =ulysses.jpg>',
              $ userpride = GT;'傲慢与prejudice&下; IMG SRC =pride.jpg>',
              $ usermockingbird =>杀死一只知更鸟< IMG SRC =mockingbird.jpg>,
              $ userroad =>'论道< IMG SRC =ontheroad.jpg>'
              );                            ASORT($ productarray);
                            的foreach($ productarray为$书=> $信息)
                                        {如果($书大于0)
                                                {回声数量。 $书。 。 $信息。 < BR>中;}
                                        }
                        }
    }
?>


解决方案

您不能直到一个新的页面请求时读取cookie的值。这是因为,cookie数据的值​​与页面请求发送。所以它不适用于访问其值,直到它被设置和新的页面请求作出后

So I'm trying to return items from an array that's made out of user inputted info from cookies, and it works fine, except when you first visit the page from the previous page, nothing shows up, and you have to refresh it to actually see the array. I have no idea why it wouldn't show up the first time around? (There are some JavaScript alerts in there that work fine. It's only the array that I'm having trouble with.) Here's my code, any advice would be great, thanks:

$usergatsby = $_COOKIE['gatq'];
$usercatcher = $_COOKIE['catcherq'];
$userwaves = $_COOKIE['wavesq'];
$userstranger = $_COOKIE['strangerq'];
$userulysses = $_COOKIE['ulyssesq'];
$userpride = $_COOKIE['prideq'];
$usermockingbird = $_COOKIE['mockingbirdq'];
$userroad = $_COOKIE['roadq'];


if ($_COOKIE['fname'] == NULL or $_COOKIE['lname'] == NULL or $_COOKIE['address'] == NULL or $_COOKIE['city'] == NULL or $_COOKIE['state'] == NULL or $_COOKIE['zip'] == NULL or $_COOKIE['email'] == NULL)
{echo "<script language='javascript'>
window.alert('You left some information on the personal info page! You will be redirected.');
    window.location.href='personal.php';</script>";
}

else
    {   


    if ($_COOKIE['gatq'] == NULL &&
        $_COOKIE['catcherq'] == NULL &&
        $_COOKIE['wavesq'] == NULL &&
        $_COOKIE['strangerq'] == NULL &&
        $_COOKIE['ulyssesq'] == NULL &&
        $_COOKIE['prideq'] == NULL &&
        $_COOKIE['mockingbirdq'] == NULL &&
        $_COOKIE['roadq'] == NULL)

            {echo "<script language='javascript'>
                window.alert('You don't have anything in your shopping cart! You will be redirected.');
                window.location.href='inventory.php';</script>";
            }

                    else
                        {$productarray = array($usergatsby=>'The Great Gatsby <img src="gatsby.jpg">',
             $usercatcher=>'Catcher in the Rye <img src="catcher.jpg">',
              $userwaves=>'The Waves <img src="waves.jpg">',
              $userstranger=>'The Stranger <img src="stranger.jpg">',
              $userulysses=>'Ulysses <img src="ulysses.jpg">',
              $userpride=>'Pride and Prejudice <img src="pride.jpg">',
              $usermockingbird=>'To Kill a Mockingbird <img src="mockingbird.jpg">',
              $userroad=>'On the Road <img src="ontheroad.jpg">'
              );

                            asort($productarray);
                            foreach ($productarray as $book=>$info)
                                        {if ($book > 0)
                                                {echo "Quantity: " . $book . " " . $info . "<br>";}
                                        }


                        }


    }


?>

解决方案

You can't read the value of a cookie until a new page request is made. This is because the value of cookie data is sent with the page request. So it isn't available for to access its value until after it is set and a new page request is made.

这篇关于从cookie的信息PHP数组:只显示您刷新页面后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆