동적 기능을 위해 쿠키를 설정하려고합니다. 나는 사용자 정의 URL 문자열을 사용하여 모든 동적 기능을 삽입 할 수 있도록 페이지 코드를 올바르게 가져올 수있었습니다.PHP 쿠키 및 동적 삽입 문제
즉
http://mysite.com/dynamicpage.php?RA_kw=Keyword-
keyword&RA_survey_id=survey_id&RA_id=123&RA_img=imgname
은 긴 ALL 변수 수신 URL에 존재하는 바와 같이, 각각의 변수에 대한 쿠키를 잘 설정한다. 재 방문시, 사용자는 모든 동적 쿠키 기능을 표시합니다. 좋은.
문제점 : 모든 PHP 변수가 URL에 존재하지 않으면 쿠키가 개별적으로 설정되지 않습니다.
<?php
/*kw = (Keywords)
survey_id=survey_id (this variable doesn't change)
id= (survey number id)
img = (name of image to be pulled from php include.)*/
$kw = null;
$survey_id = null;
$id = null;
$img = null;
if (isset($_COOKIE['RA_kw'])
&& isset($_COOKIE['RA_survey_id'])
&& isset($_COOKIE['RA_id'])
&& isset($_COOKIE['RA_img']))
{
//if cookie variables are already set
//To Do Here: maybe redirect
$kw = $_COOKIE['RA_kw'];
$survey_id = $_COOKIE['RA_survey_id'];
$id = $_COOKIE['RA_id'];
$img = $_COOKIE['RA_img'];
$_GET['RA_kw'] = $kw;
$_GET['RA_survey_id'] = $survey_id;
$_GET['RA_id'] = $id;
$_GET['RA_img'] = $img;
}
else
{
//if cookie varialbes are not set yet
//set Cookies
if (isset($_GET['RA_kw'])){
//kw parameter is set
setcookie('RA_kw', $_GET['RA_kw'], time() + 60*60*24*30); //expires in 30 days.
$kw = $_GET['RA_kw'];
}
if (isset($_GET['RA_survey_id'])){
//survey_id parameter is set
setcookie('RA_survey_id', $_GET['RA_survey_id'], time() + 60*60*24*30); //expires in 30 days.
$survey_id = $_GET['RA_survey_id'];
}
if (isset($_GET['RA_id'])){
//id parameter is set
setcookie('RA_id', $_GET['RA_id'], time() + 60*60*24*30); //expires in 30 days.
$id = $_GET['RA_id'];
}
if (isset($_GET['RA_img'])){
//img parameter is set
setcookie('RA_img', $_GET['RA_img'], time() + 60*60*24*30); //expires in 30 days.
$img = $_GET['RA_img'];
}
//To Do Here: default page
}
?>
만큼 여기 즉
은 PHP 코드의 @ user973254가 옳다면 변수를 정의하기 전에 각각의 '쿠키'조건을 확인해야합니다. $ _COOKIE [ 'RA_ID']'가 정해진 것이 아니라면'$ id = $ _COOKIE [ 'RA_ID'];'를 실행하는 것은 "훌륭합니다". –