Fri 29 Dec 2006 11:23:21
พี่รับช่วยดูโค้ดให้ที ครับ คือผมลองทำเวปให้ เปลี่ยมเทมเพลทเว็ปได้
โดยผมให้ GET ค่า เทมเพลทจากบราวเซอร์ ได้เป็น
index.php?style=1 เทมเพลท 1
index.php?style=2 เทมเพลท 2
index.php?style=3 เทมเพลท 3
ไฟล์ style.php
<?
###################################
$style_1 = "style_default_theme";
$style_2 = "style_extream_theme";
$style_3 = "style_sunflower_theme";
###################################
if($_GET["style"]=='1') {
$webstyle = $style_1;
}
else if($_GET["style"]=='2') {
$webstyle = $style_2;
}
else if($_GET["style"]=="3"){
$webstyle = $style_3;
}
else if($_GET !=""){
$webstyle = $style_3; //
}
?>
ไฟล์ template ก็มีไปแต่ละตัวครับ
style_default_theme
style_extream_theme
style_sunflower_theme
==========================
คือ จะ ใช้ cookie หรือ session รับค่าที่ GET ไว้ยังไงครับให้มันจำค่า ที่ได้ GET เทมเพลทแต่ละอันไปตลอดครับ อย่าง register.php&style=1 หรือ register.php&style=2 ในแต่ละเทมเพลทหรือในแต่และไฟล์ครับแนะนำด้วยครับ
Sat 30 Dec 2006 18:44:49
if($_GET["style"]=='1') {
$webstyle = $style_1;
SetCookie("cookie_name_style",$webstyle,time()+2592000);
}
else if($_GET["style"]=='2') {
$webstyle = $style_2;
SetCookie("cookie_name_style",$webstyle,time()+2592000);
}
else if($_GET["style"]=="3"){
$webstyle = $style_3;
SetCookie("cookie_name_style",$webstyle,time()+2592000);
}
else if($_GET !=""){
$webstyle = $style_3; //
SetCookie("cookie_name_style",$webstyle,time()+2592000);
}
ลองดูครับ
Sat 30 Dec 2006 20:39:51
ไม่ได้ครับพี่ท่าน หรือว่าต้อง setcookie ใน หน้าแรกด้วย
ไฟล์ index.php
<?
###################################
include('connect_db.php');
include('connect_config.php');
include('style.php');
if(($mode=="admin") or ($mode=="user")) {
include('admin_chk.php');
}
?>
<html>
<head>
<title><?=$cf_title;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<? $version = "LMS2.0.2 [st]"; ?>
<SCRIPT language=JavaScript src="_javascript.js"></SCRIPT>
<script language="Javascript1.2"><!-- // load htmlarea
_editor_url = ""; // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera') >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
document.write(' language="Javascript1.2"></scr' + 'ipt>');
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// --></script>
<style type="text/css">
<!--
body { margin: 0px 0px; padding: 0px 0px}
a:link { color: #005CA2; text-decoration: none}
a:visited { color: #005CA2; text-decoration: none}
a:active { color: #0099FF; text-decoration: underline}
a:hover { color: #0099FF; text-decoration: underline}
-->
</style>
</head>
<?
include($webstyle .".php");
?>
</html>
===================
ไฟล์ style.php
<?
###################################
$style_1 = "style_default_theme";
$style_2 = "style_extream_theme";
$style_3 = "style_sunflower_theme";
###################################
if($_GET["style"]=='1') {
$webstyle = $style_1;
SetCookie("cookie_name_style",$webstyle,time()+2592000);
}
else if($_GET["style"]=='2') {
$webstyle = $style_2;
SetCookie("cookie_name_style",$webstyle,time()+2592000);
}
else if($_GET["style"]=="3"){
$webstyle = $style_3;
SetCookie("cookie_name_style",$webstyle,time()+2592000);
}
else if($_GET !=""){
$webstyle = $style_3; //
SetCookie("cookie_name_style",$webstyle,time()+2592000);
}
?>
Sat 30 Dec 2006 21:13:34
<?
###################################
$style_1 = "style_default_theme";
$style_2 = "style_extream_theme";
$style_3 = "style_sunflower_theme";
###################################
if($cookie_name_style){
$webstyle=$cookie_name_style;
}
if($_GET["style"]=='1') {
$webstyle = $style_1;
SetCookie("cookie_name_style",$webstyle,time()+2592000);
}
else if($_GET["style"]=='2') {
$webstyle = $style_2;
SetCookie("cookie_name_style",$webstyle,time()+2592000);
}
else if($_GET["style"]=="3"){
$webstyle = $style_3;
SetCookie("cookie_name_style",$webstyle,time()+2592000);
}
else if($_GET !=""){
$webstyle = $style_3; //
SetCookie("cookie_name_style",$webstyle,time()+2592000);
}
?>
ลองดูอีกทีครับ
Mon 1 Jan 2007 19:16:22
if($cookie_name_style){
$webstyle=$cookie_name_style;
}
if($_SESSION['style'] == '1'){
//if($_GET["style"]=='1') {
$webstyle = $style_1;
setcookie("cookie_name_style", $webstyle, time()+(3600 * 24 * 365)); # สร้าง cookie
}
//else if($_GET["style"]=='2') {
else if($_SESSION['style'] == '2') {
$webstyle = $style_2;
setcookie("cookie_name_style", $webstyle, time()+(3600 * 24 * 365)); # สร้าง cookie
}
else if($_SESSION['style'] == '3') {
$webstyle = $style_3;
setcookie("cookie_name_style", $webstyle, time()+(3600 * 24 * 365)); # สร้าง cookie
}
else if($_SESSION !=""){
$webstyle = $style_3; //
setcookie("cookie_name_style", $webstyle, time()+(3600 * 24 * 365)); # สร้าง cookie
}
ผมลองมาใช้ SESSION ได้นะครับพี่ Davinci แต่ภาพ ไม่ชึ้นเลยครับไม่รุ้ว่า เพราะอะไรครับ
Mon 1 Jan 2007 21:23:16
Tue 2 Jan 2007 11:20:55
Tue 2 Jan 2007 13:32:10
Tue 2 Jan 2007 13:34:20
Tue 2 Jan 2007 18:50:15
<? ISAN_LANG
หลุด ไม่หวาดไม่หวั่น โทรไปแจ้งก็เสย ภาษาลาวบ้านผมนะ 55 นอกเรื่องไป ?>
(-_-) แต่ยังไงก็ขอบคุณเสมอๆๆครับ สำหรับที่นี่อาจจะได้คำตอบที่ตรงๆๆบ้างหรือ อ้อมๆๆ บ้างก็เป็นเรื่องธรรมดา ที่นี่ให้ความรู้เยอะอีกที่หนึ่ง ขอบคุณมากๆๆครับ เดี่ยวผมทำได้จะเอามาโชว์ ท่านพี่ Davinci นะครับ
Fri 5 Jan 2007 14:27:31
best regards
{[header_section]}
{[content_section]}
{[footer_section]}
จากนั้นก็ replace ด้วยค่า template ที่ต้องการครับ เช่น
preg_replace("/({[[a-z_]]})/", $template, $source);
ประมาณนี้ครับ
อีกวิธีก็เขียน template แล้วเก็บลง db ครับ เช่น
_________________________________________
| templateid | section | datatext |
-------------------------------------------------------
| 1 | header | <div style="color:#FF0000;">...|
-------------------------------------------------------
| 2 | header | <div style="colot:#E2E2E2;">...|
-------------------------------------------------------
| 3 | header | <div style="colot:#000055;">...|
วิธีนี้ใช้พลังของ db เยอะมากแต่ก็ดูยืดหยุ่นมากครับ
จากที่ผมดูโค๊ดนี้น่าจะหมายถึง visitor สามารถเปลี่ยน template ได้เองใช่หรือไม่ครับเนื่องจากเห็นว่าใช้ Cookie และ Session ในการเก็บค่าต่างๆ ซึ่ง policy แบบนี้ผมยังไม่เคยเห็นเหมือนกันครับ
ปล. ยังไม่เคยเขียนใช้งานจริงครับ

















