2011-07-11 60 views
0

我有一個JQModal警報,需要首次訪問客戶端站點時纔會出現,但是當從站點內再次訪問索引頁時不會再顯示。如果可能的話,我在設置會話cookie方面並不真正,所以我需要一些明確的幫助。我已經創建了一個簡短的頁面,用它來測試:URL是http://www.caycecookbook.com/pop_ups/jqm_onDocReady/code.php。我在這裏附上代碼。需要關於會話腳本的幫助,僅顯示JQModal彈出窗口一次

<?php session_start(); 
    if($_SESSION['visited']){ 
     //don't show the modal box 
    } else { 
     $_SESSION['visited'] = true; 
    //show modal box; 
    } 
?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1   /DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 

<title>Cayce CookBook</title> 

<!-- >>>>>>>>>> TOGGLE-INSERT DEPENDENCIES >>>>>>>>>> --> 
<!-- >>>>>>>>>> TOGGLE-INSERT DEPENDENCIES >>>>>>>>>> --> 
<link href="css/vwd_up.css" rel="stylesheet" type="text/css" /> 
<script src="scripts/main.js" type="text/javascript"></script> 
<!-- <<<<<<<<<< TOGGLE-INSERT DEPENDENCIES <<<<<<<<<< --> 
<!-- <<<<<<<<<< TOGGLE-INSERT DEPENDENCIES <<<<<<<<<< --> 


<!-- >>>>>>>>>> jqMODAL DEPENDENCIES >>>>>>>>>> --> 
<!-- >>>>>>>>>> jqMODAL DEPENDENCIES >>>>>>>>>> --> 
<script type="text/javascript" src="scripts/jquery-1.5.1.js"></script> 
<script type="text/javascript" src="scripts/jqModal.js"></script> 
<style type="text/css"> 
/* Optional: image cacheing. Any images contained in this div will be 
    loaded offscreen, and thus cached. Caching CSS created with the help of; 
    Klaus Hartl <[email protected]> */ 
@media projection, screen { 
    div.imgCache { position: absolute; left: -8000px; top: -8000px; } 
    div.imgCache img { display:block; } 
} 
@media print { div.imgCache { display: none; } } 
</style> 
<style type="text/css"> 
/* jqModal base Styling courtesy of; 
    Brice Burgess <[email protected]> */ 

/* The Window's CSS z-index value is respected (takes priority). If none is supplied, 
    the Window's z-index value will be set to 3000 by default (in jqModal.js). You 
    can change this value by either; 
    a) supplying one via CSS 
    b) passing the "zIndex" parameter. E.g. (window).jqm({zIndex: 500}); */ 
.jqmWindow { 
    display: none; 
    position: fixed; 
    top: 5%; 
    left: 50%; 
    margin-left: -265px; 
    width: 530px; 
    /*width: auto;*/ 
    background-color:#777777; 
    color: #333; 
    border: 1px solid black; 
    padding: 0px; 
} 
.jqmOverlay { background-color: #000; } 
/* Fixed posistioning emulation for IE6 
    Star selector used to hide definition from browsers other than IE6 
    For valid CSS, use a conditional include instead */ 
* html .jqmWindow { 
    position: absolute; 
    top: expression((document.documentElement.scrollTop || document.body.scrollTop) + Math.round(17 * (document.documentElement.offsetHeight || document.body.clientHeight)/100) + 'px'); 
} 
</style> 
<!-- <<<<<<<<<< jqMODAL DEPENDENCIES <<<<<<<<<< --> 
<!-- <<<<<<<<<< jqMODAL DEPENDENCIES <<<<<<<<<< --> 
</head> 

<body> 

<script type="text/javascript"> 
    $(document).ready(function() { 
     $('#rename').jqm(); 
     $('#rename').jqmShow(); // This is the line you need to add. 
    }); 
</script> 
<!-- POP-UP DIV --> 
<DIV class="jqmWindow" id="rename" style="padding:18px 0px 12px 0px;"> 
<TABLE align="center" width="530" border="0" cellspacing="0" cellpadding="0" bgcolor="#7777777"> 
<TR><TD align="center"><P style="margin: 12px 12px 12px 12px;"><img src="images/hey_there.jpg"  width="504" height="360" border="0"></p></td></tr> 
<TR><TD align="center" valign="middle"><P style="margin:6px 0px 0px 0px;"><a href="#"  class="jqmClose" style="text-decoration:none; color:#ffffff;; font-family: arial, helvetica,  verdana, sans-serif; font-size:12px; font-weight:bold;">Close</a></p></td></tr> 
</table> 
</div> 

</body> 
</html> 

回答

1

您無法從PHP明確控制js/html/css行爲。
你有兩個選擇

1)不包括對模式對話框的JavaScript如果$_SESSION['visited']是真的

2)回送真/假從$_SESSION['visited'] JavaScript代碼,做一個邏輯有

代碼對於第一個選項:

<?php session_start(); ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1   /DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 

<title>Cayce CookBook</title> 
<?php 
if($_SESSION['visited']){ 

} else { 
    $_SESSION['visited'] = true; 
?> 

<!-- >>>>>>>>>> jqMODAL DEPENDENCIES >>>>>>>>>> --> 
<!-- >>>>>>>>>> jqMODAL DEPENDENCIES >>>>>>>>>> --> 
<script type="text/javascript" src="scripts/jquery-1.5.1.js"></script> 
<script type="text/javascript" src="scripts/jqModal.js"></script> 
<style type="text/css"> 
/* Optional: image cacheing. Any images contained in this div will be 
loaded offscreen, and thus cached. Caching CSS created with the help of; 
Klaus Hartl <[email protected]> */ 
@media projection, screen { 
div.imgCache { position: absolute; left: -8000px; top: -8000px; } 
div.imgCache img { display:block; } 
} 
@media print { div.imgCache { display: none; } } 
</style> 
<style type="text/css"> 
/* jqModal base Styling courtesy of; 
    Brice Burgess <[email protected]> */ 

/* The Window's CSS z-index value is respected (takes priority). If none is supplied, 
    the Window's z-index value will be set to 3000 by default (in jqModal.js). You 
    can change this value by either; 
    a) supplying one via CSS 
    b) passing the "zIndex" parameter. E.g. (window).jqm({zIndex: 500}); */ 
.jqmWindow { 
    display: none; 
    position: fixed; 
    top: 5%; 
    left: 50%; 
    margin-left: -265px; 
    width: 530px; 
    /*width: auto;*/ 
    background-color:#777777; 
    color: #333; 
    border: 1px solid black; 
    padding: 0px; 
} 
.jqmOverlay { background-color: #000; } 
/* Fixed posistioning emulation for IE6 
     Star selector used to hide definition from browsers other than IE6 
     For valid CSS, use a conditional include instead */ 
* html .jqmWindow { 
     position: absolute; 
     top: expression((document.documentElement.scrollTop || document.body.scrollTop) +   Math.round(17 * (document.documentElement.offsetHeight || document.body.clientHeight)/100)  + 'px'); 
} 
</style> 
<!-- <<<<<<<<<< jqMODAL DEPENDENCIES <<<<<<<<<< --> 
<!-- <<<<<<<<<< jqMODAL DEPENDENCIES <<<<<<<<<< --> 

<?php 
} 
?> 



<!-- >>>>>>>>>> TOGGLE-INSERT DEPENDENCIES >>>>>>>>>> --> 
<!-- >>>>>>>>>> TOGGLE-INSERT DEPENDENCIES >>>>>>>>>> --> 
<link href="css/vwd_up.css" rel="stylesheet" type="text/css" /> 
<script src="scripts/main.js" type="text/javascript"></script> 
<!-- <<<<<<<<<< TOGGLE-INSERT DEPENDENCIES <<<<<<<<<< --> 
<!-- <<<<<<<<<< TOGGLE-INSERT DEPENDENCIES <<<<<<<<<< --> 
</head> 

<body> 

<script type="text/javascript"> 
    $(document).ready(function() { 
     $('#rename').jqm(); 
     $('#rename').jqmShow(); // This is the line you need to add. 
    }); 
</script> 
<!-- POP-UP DIV --> 
<DIV class="jqmWindow" id="rename" style="padding:18px 0px 12px 0px;"> 
<TABLE align="center" width="530" border="0" cellspacing="0" cellpadding="0"  bgcolor="#7777777"> 
<TR><TD align="center"><P style="margin: 12px 12px 12px 12px;"><img  src="images/hey_there.jpg"  width="504" height="360" border="0"></p></td></tr> 
<TR><TD align="center" valign="middle"><P style="margin:6px 0px 0px 0px;"><a href="#"  class="jqmClose" style="text-decoration:none; color:#ffffff;; font-family: arial, helvetica,  verdana, sans-serif; font-size:12px; font-weight:bold;">Close</a></p></td></tr> 
</table> 
</div> 

</body> 
</html> 
+0

得到這個錯誤: 警告:在session_start()[function.session啓動]:無法發送會話緩存限制器 - 已經發送了頭(輸出開始/ home6/cayceweb /的public_html/caycecookbook/pop_ups/jqm_onDocReady/code.php:7)in /home6/cayceweb/public_html/caycecookbook/pop_ups/jqm_onDocReady/code.php on line 7 – Cayce

+0

right,my fault,repaired code –

0

將下面的代碼替換爲下面的代碼,我在下面的代碼中更改了3個東西。

1> php代碼的位置。我把PHP代碼在文件的結尾

2>曲奇,而不是會議

3> JavaScript彈出opning代碼有一些變化

請申請以下文件後,你仍然有一些問題,不是讓我知道你的概率。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1   /DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 

<title>Cayce CookBook</title> 

<!-- >>>>>>>>>> TOGGLE-INSERT DEPENDENCIES >>>>>>>>>> --> 
<!-- >>>>>>>>>> TOGGLE-INSERT DEPENDENCIES >>>>>>>>>> --> 
<link href="css/vwd_up.css" rel="stylesheet" type="text/css" /> 
<script src="scripts/main.js" type="text/javascript"></script> 
<!-- <<<<<<<<<< TOGGLE-INSERT DEPENDENCIES <<<<<<<<<< --> 
<!-- <<<<<<<<<< TOGGLE-INSERT DEPENDENCIES <<<<<<<<<< --> 


<!-- >>>>>>>>>> jqMODAL DEPENDENCIES >>>>>>>>>> --> 
<!-- >>>>>>>>>> jqMODAL DEPENDENCIES >>>>>>>>>> --> 
<script type="text/javascript" src="scripts/jquery-1.5.1.js"></script> 
<script type="text/javascript" src="scripts/jqModal.js"></script> 
<style type="text/css"> 
/* Optional: image cacheing. Any images contained in this div will be 
    loaded offscreen, and thus cached. Caching CSS created with the help of; 
    Klaus Hartl <[email protected]> */ 
@media projection, screen { 
    div.imgCache { position: absolute; left: -8000px; top: -8000px; } 
    div.imgCache img { display:block; } 
} 
@media print { div.imgCache { display: none; } } 
</style> 
<style type="text/css"> 
/* jqModal base Styling courtesy of; 
    Brice Burgess <[email protected]> */ 

/* The Window's CSS z-index value is respected (takes priority). If none is supplied, 
    the Window's z-index value will be set to 3000 by default (in jqModal.js). You 
    can change this value by either; 
    a) supplying one via CSS 
    b) passing the "zIndex" parameter. E.g. (window).jqm({zIndex: 500}); */ 
.jqmWindow { 
    display: none; 
    position: fixed; 
    top: 5%; 
    left: 50%; 
    margin-left: -265px; 
    width: 530px; 
    /*width: auto;*/ 
    background-color:#777777; 
    color: #333; 
    border: 1px solid black; 
    padding: 0px; 
} 
.jqmOverlay { background-color: #000; } 
/* Fixed posistioning emulation for IE6 
    Star selector used to hide definition from browsers other than IE6 
    For valid CSS, use a conditional include instead */ 
* html .jqmWindow { 
    position: absolute; 
    top: expression((document.documentElement.scrollTop || document.body.scrollTop) + Math.round(17 * (document.documentElement.offsetHeight || document.body.clientHeight)/100) + 'px'); 
} 
</style> 
<!-- <<<<<<<<<< jqMODAL DEPENDENCIES <<<<<<<<<< --> 
<!-- <<<<<<<<<< jqMODAL DEPENDENCIES <<<<<<<<<< --> 
</head> 

<body> 

<script type="text/javascript"> 
    <?php if(!isset($_COOKIE["visited"]) || $_COOKIE["visited"] != true): ?> 
     $('#rename').jqm(); 
     $('#rename').jqmShow(); // This is the line you need to add. 
    <?php endif; ?> 
</script> 
<!-- POP-UP DIV --> 
<DIV class="jqmWindow" id="rename" style="padding:18px 0px 12px 0px;"> 
<TABLE align="center" width="530" border="0" cellspacing="0" cellpadding="0" bgcolor="#7777777"> 
<TR><TD align="center"><P style="margin: 12px 12px 12px 12px;"><img src="images/hey_there.jpg"  width="504" height="360" border="0"></p></td></tr> 
<TR><TD align="center" valign="middle"><P style="margin:6px 0px 0px 0px;"><a href="#"  class="jqmClose" style="text-decoration:none; color:#ffffff;; font-family: arial, helvetica,  verdana, sans-serif; font-size:12px; font-weight:bold;">Close</a></p></td></tr> 
</table> 
</div> 
<?php 
    if(!isset($_COOKIE["visited"]) || $_COOKIE["visited"] != true) 
    { 
     $expireTime = time() + (60 * 60 * 24 * 1); 
     // Set cookie for 1 day or 24 hour from current time 
     setcookie("visited", true,); 
    } 
?> 
</body> 
</html> 
+0

嗨;感謝您的幫助。我(應用代碼並啓動,但得到此錯誤消息: – Cayce

+0

解析錯誤:語法錯誤,意外')'在/home6/cayceweb/public_html/caycecookbook/pop_ups/jqm_onDocReady/code.php在線85 – Cayce

+0

線85是一個讀取:setcookie(「visited」,true,);幾乎在頁面的末尾。 – Cayce