Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将cookie更改为会话?_Php_Session_Cookies - Fatal编程技术网

Php 如何将cookie更改为会话?

Php 如何将cookie更改为会话?,php,session,cookies,Php,Session,Cookies,我不熟悉会话和cookie。像瓷砖一样,我想将cookie更改为会话。我只是从这里的链接得到代码:? 我试过一些方法,但没有成功 在doctype之前: <?php $theme1 = business; $theme2 = modern; $theme3 = web2; if(isset($_POST['style'])) {setcookie('style', $_POST['style'], time()+(60*60*24*1000)); $style=$_POST['style'

我不熟悉会话和cookie。像瓷砖一样,我想将cookie更改为会话。我只是从这里的链接得到代码:? 我试过一些方法,但没有成功

在doctype之前:

<?php
$theme1 = business;
$theme2 = modern;
$theme3 = web2;
if(isset($_POST['style']))
{setcookie('style', $_POST['style'], time()+(60*60*24*1000));
$style=$_POST['style'];}
elseif(isset($_COOKIE['style']))
{$style=$_COOKIE['style'];}
else
{$style=$theme1;} ?>
负责人:


如果要使用会话销毁cookiee,只需将时间参数留空即可

    setcookie('style', $_POST['style']);

就足够了…

这真的很简单。从PHP,只需调用


如果要禁用PHP会话的Cookie,只需调用

如果要使用会话而不是Cookie,请将开始代码更改为(未测试):



会话中的cookie是什么意思..你的意思是cookiee应该在会话结束时销毁吗?我的意思是,我只想使用会话,而不是cookie。将cookie更改为会话。
<body>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"> 
<select name="style"> <option <?php echo "value='$theme1'";
if($style == $theme1)
{
echo "selected='selected'";
}
?>><?php echo $theme1; ?></option>
<option <?php
echo "value='$theme2'";
if($style == $theme2)
{
echo "selected='selected'";
}
?>><?php echo $theme2; ?></option>
<option <?php
echo "value='$theme3'";
if($style == $theme3)
{
echo "selected='selected'";
}
?>><?php echo $theme3; ?></option>
</select><input type="submit" />
</form>
</body>
session_start();
$theme1
$theme2
$theme3
if(isset($_POST['style'])){
$style=$_POST['style'];}
elseif(isset($_SESSION['style']))
{$style=$_SESSION['style'];}
else
{$style=$theme1;} 
?>
<link rel="stylesheet" type="text/css" href="<?php echo $_SESSION['style']?>" />
    setcookie('style', $_POST['style']);
<?php
session_start();
$theme1 = business;
$theme2 = modern;
$theme3 = web2;
if (isset($_POST['style'])) {
    $_SESSION['style'] = $_POST['style'];
    $style=$_POST['style'];
} else if (isset($_SESSION['style'])) {
    $style=$_SESSION['style'];
} else {
    $style=$theme1;
} ?>