Wml + Xhtml In Same Php File ?
Started on the old forum in July 2007 · view the original in the archive · old links redirect here
hello,
try this:
<?php if(!isset($_GET['case'])) $_GET['case'] = ''; switch($_GET['case']) { case ''; echo "START CASE"; break; case '1': include ('headwml.php'); echo "CASE 1 WML"; include ('footwml.php'); break; case '2': include ('headxhtml.php'); echo "CASE 2 XHTML"; include ('footxhtml.php'); break; case '3': echo "CASE 3 WHAT YOU WANT "; } ?>that is case.php; first case must be : yourserver.com/case.php - start case second case must be : yourserver.com/case.php?case=1 - wml third case must be: yourserver.com/case.php?case=2 - xhtml
you may need to include some headers and footers for wml and xhtml.
heres my way put this into core
global $HTTP_USER_AGENT,$HTTP_ACCEPT;
$script="wml";
$browser=explode("/",$HTTP_USER_AGENT);
//feel free 2 add more browsers here//
if(strpos($_SERVER["HTTP_USER_AGENT"],"Firefox")==true){$script="wml";}
else if($browser[0]=="Mozilla"){$script="html";}
else if($browser[0]=="Opera"){$script="xhtml";}
else if(strpos(strtoupper($HTTP_ACCEPT),"XHTML+XML")>0){$script="xhtml";}
function header_type()
{
global $script;
if($script=="xhtml"){
header('Content-type: application/vnd.wap.xhtml+xml');
echo "<?xml version=\"1.0\"?>
<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\" \"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">";
}
else if($script=="html"){
header('Content-type: text/html');
echo "<?xml version=\"1.0\"?>
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">
<html>";
}
else if($script=="wml"){
header("Content-type: text/vnd.wap.wml");
echo "<?xml version=\"1.0\"?>
<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"". " \"http://www.wapforum.org/DTD/wml_1.1.xml\">
<wml>";
}
}
function head_tag($title,$theme_opt,$uid)
{
global $script;
if($theme_opt==0){$theme[0]="white_medium.css";}
if($script=="html"){
if($theme_opt==1){
$theme=mysql_fetch_array(mysql_query("SELECT theme FROM profiles WHERE uid='".getuid_nick($uid)."'"));
}
echo "<head>
<title>$title</title>
<link rel=\"stylesheet\" type=\"text/css\" href=\"themes/html_$theme[0]\">
</head>
<body onLoad=\"show3()\">";
}
else if($script=="xhtml"){
if($theme_opt==1){
$theme=mysql_fetch_array(mysql_query("SELECT theme FROM profiles WHERE uid='".getuid_nick($uid)."'"));
}
echo "<head>
<title>$title</title>
<link rel=\"stylesheet\" type=\"text/css\" href=\"themes/$theme[0]\">
</head>
<body>";
}else if($script=="wml"){
echo "<card id=\"main\" title=\"$title\">";
}
}
function foot_tag()
{
global $script;
if(($script=="html")||($script=="xhtml")){
echo "</body>
</html>";
}else if($script=="wml"){
echo "</card>
</wml>";
}
}
function database_error()
{
global $script;
echo head_tag("Error!!!",0,0);
if(($script=="xhtml")||($script=="html")){
echo "
<center>
";
}
else if($script=="wml"){
echo "
<p align=\"center\">
";
}
echo "
<img src=\"images/notok.gif\" alt=\"!\"/>
[b][b]Error! Cannot Connect To Database...[/b][/b]
This error happens usually when backing up the database, please be patient...
";
if(($script=="xhtml")||($script=="html")){
echo "
</center>
";
}
else if($script=="wml"){
echo "
</p>
";
}
echo foot_tag();
exit();
}
thern add this in the pages
<?php include("blocked.php"); include("core.php"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header_type(); $action = $_GET["action"]; $mode = $_GET["mode"]; $sid = $_GET["sid"]; $who = $_GET["who"]; if(!connectdb()) { echo database_error(); } cleardata(); if(!islogged($sid)) { echo head_tag("Error!!!",0,0); echo session_expired(); echo foot_tag(); exit(); } /////////////////////////INDEX///////////////////////// if(($action=="")&&($mode=="")) { addonline(getuid_sid($sid),"Index","index.php"); echo head_tag(getnick_sid($sid)." index",1,getnick_sid($sid)); if(($script=="html")||($script=="xhtml")){echo "**Index**";} else if($script=="wml"){echo " **Index** ";} ////script data goes here////// echo foot_tag(); } ?>i dont see refference about LAVA script or else in the first post . External image (may be gone)
i know it aint exactly the prettiest script in the world (i coded it all just in the last 5minutes), but hey, its free and ive even been nice enough to add comments that explain what is going on so dont you dare complain .. or else External image (may be gone)
and i know this means having twice as many pages, but the nice advantage is that you can edit it so that the filepaths for each filetype are set in config.php for example, and other programming languages can easily be added / removed .. =]
anyways, enough of me rambling on and take a look at this lol ..
/// get what the link says the page type should be
$page = $_GET['page'];
/// make sure what has been given is either wml or xhtml .. this is needed to prevent code injections .. just a quick warning that this isnt totally secure so dont take it for granted that it is..
if($page == "wml"){
$pagetype = "wml";
}elseif($page == "xhtml"){
$pagetype="xhtml";
else {
//// some script to figure out what the browser accepts .. there are plenty on here or you can google for one ... then set $pagetype accordingly =]
}
////// make sure that the variables below here are ones that youve set and are validated somehow (for example, if functions)
/// check the value of $pagetype is exactly what you wanted
if(($pagetype == "wml") || ($pagetype == "xhtml") && ($pagetype !== "")){
if($pagetype == "wml"){
include("PATH TO WML FILE\PAGE.WML");
}elseif($pagetype == "xhtml"){
include("PATH TO XHTML FILE\PAGE.XHTML");
}else{
echo 'this shouldnt ever happen, unless the if(($pagetype == "wml") || ($pagetype == "xhtml") && ($pagetype !== "")) function messed up somehow';
}
}
?>
style.class.php
<?php
// wml + xhtml style class By Midnex 2007
// Visit my site at [url="http://wap-online.net"]http://wap-online.net[/url]
// Skype: midnex
// ICQ : 350-772-392
// Email: [email]midnex@gmail.com[/email]
class style {
var $style;
var $body = '';
//This is optional if you want to detect browser in other way, you can write line $style->style = 'wml'; in your index.php to change style
function style()
{
list($browser) = explode("/", $_SERVER['HTTP_USER_AGENT']);
$browser_array = array('Mozilla','Opera');
$style = 0;
for($i = 0; $i < count($browser_array); $i++)
{
if($browser == $browser_array[$i])
{
$style++;
}
}
if($style == 0)
{
$this->style = 'wml';
}
else
{
$this->style = 'xhtml';
}
}
function add_img($url,$text,$br)
{
if($this->style == 'wml')
{
$this->body .= '[img]'.$url.'[/img]';
if($br)
{
$this->body .= '
';
}
}
if($this->style == 'xhtml')
{
$this->body .= '[img]'.$url.'[/img]';
if($br)
{
$this->body .= '
';
}
}
$this->body .= "\n";
}
function start_p($align='left')
{
if($this->style == 'wml')
{
$this->body .= '<p align="'.$align.'">';
}
if($this->style == 'xhtml')
{
$this->body .= '<p class="'.$align.'">';
}
$this->body .= "\n";
}
function end_p()
{
$this->body .= '</p>';
}
function start_page($title)
{
if($this->style == 'wml')
{
$this->body .= '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd">';
$this->body .= '<wml><card id="index" title="'.$title.'">';
$this->body .= "\n";
}
if($this->style == 'xhtml')
{
$this->body .= '<?xml version="1.0" encoding="ISO-8859-1"?><!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>
<title>'.$title.'</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>';
$this->body .= "\n";
}
}
function end_page()
{
if($this->style == 'wml')
{
$this->body .= '</card></wml>';
}
if($this->style == 'xhtml')
{
$this->body .= '</body></html>';
}
$this->body .= "\n";
}
function headers()
{
if($this->style == 'wml')
{
header("Content-type: text/vnd.wap.wml;charset=utf-8");
header("Cache-Control: no-store, no-cache, must-revalidate");
}
if($this->style == 'xhtml')
{
header("Content-type: text/html");
header("Cache-Control: no-store, no-cache, must-revalidate");
}
}
function add_link($url,$text,$class='title',$br=true)
{
if($this->style == 'wml')
{
$this->body .= '<anchor>'.$text.'<go href="'.$url.'"></go></anchor>';
}
if($this->style == 'xhtml')
{
if(!empty($class))
{
$this->body .= '[url="'.$url.'"]'.$text.'[/url]';
}
else
{
$this->body .= '[url="'.$url.'"]'.$text.'[/url]';
}
}
if($br)
{
$this->body .= $this->do_br();
}
$this->body .= "\n";
}
function img_link($url,$img_url,$text,$br)
{
if($this->style == 'wml')
{
$this->body .= '<anchor>';
$this->body .= $this->add_img($img_url,$text,false);
$this->body .= '<go href="'.$url.'"></go></anchor>';
if($br)
{
$this->body .= '
';
}
}
if($this->style == 'xhtml')
{
$this->body .= '<a href="'.$url.'">';
$this->body .= $this->add_img($img_url,$text,false);
$this->body .= '</a>';
if($br)
{
$this->body .= '
';
}
}
$this->body .= "\n";
}
function do_br($sk=1)
{
$this->body .= str_repeat('
',$sk);
}
function simple_text($text,$br=false)
{
$this->body .= $text;
if($br)
{
$this->body .= $this->do_br();
}
$this->body .= "\n";
}
function show_body()
{
echo $this->body;
}
}
?>
index.php
<?php
// wml + xhtml style class By Midnex 2007
// Visit my site at [url="http://wap-online.net"]http://wap-online.net[/url]
// Skype: midnex
// ICQ : 350-772-392
// Email: [email]midnex@gmail.com[/email]
include('style.class.php');
$style = new style;
//Leave commented if you want the class will detect browser automatically.
//$style->style = $_GET['style']; wml/xhtml
//$style->style = 'wml';
//$style->style = 'xhtml';
$style->headers();
$style->start_page('Wap-Online.Net');
$style->start_p('center');
$style->add_img('[url]http://wap-online.net/images/logo.gif','Logo',true[/url]);
$style->simple_text('Hello everyone, im glad you visited my site;)',true);
$style->add_link('[url]http://wap-online.net','Wap-Online.Net'[/url]);
$style->end_p();
$style->end_page();
$style->show_body();
?>
Got questions ? External image (may be gone) Ask External image (may be gone)
every1 has a different way lol. here's mine config.php
<?php
$themedir = "default";
$pgtitle = "wizardwap.us";
$prtname = "wizardwap.us";
$copyright = "© wizardwap.us";
?>
core.php
<?php
include("config.php");
connectdb();
define ('WAP','text/vnd.wap.wml');
define ('WEB','application/xhtml+xml');
$o = $_GET["o"];
if($o=="wml")
{
$mime = "text/vnd.wap.wml";
}else if($o=="xml")
{
$mime = "application/xhtml+xml";
}else if($o=="")
{
///$getmime = mysql_fetch_array(mysql_query("SELECT site_mime FROM membertable WHERE id='".$uid."'"));
///$v = $getmime[0];
$v == "";
if($v=="wml")
{
$mime = "text/vnd.wap.wml";
}else if($v=="xml")
{
$mime = "application/xhtml+xml";
}else if($v=="")
{
$mtype = "";
//$mtype = "application/xhtml+xml";// for debugging
if($mtype=="")
{
$mime = ((stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) ? "application/xhtml+xml" : "text/vnd.wap.wml");
}else{
$mime = $mtype;
}
}
}
$charset = "UTF-8";
header("content-type: $mime; charset=$charset");
function waphead($pgtitle,$uid)
{
$rets = "<wml><card id=\"main\" title=\"$pgtitle\">";
return $rets;
}
function wapfoot()
{
$rets = "</card></wml>";
return $rets;
}
function webhead($pgtitle,$uid)
{
global $mime, $charset;
$themedir = "default";
$rets = "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" >";
$rets .= "<head>";
$rets .= "<title>$pgtitle</title>";
$rets .= "<meta http-equiv=\"Content-Type\" content=\"".$mime."; charset=".$charset."\" />";
$rets .= "<meta http-equiv=\"Cache-Control\" content=\"no-cache\" />";
$rets .= "<meta http-equiv=\"Cache-Control\" content=\"must-revalidate\" />";
$rets .= "<link rel=\"StyleSheet\" type=\"text/css\" href=\"../themes/".$themedir."/style/style.css\" />";
$rets .= "</head><body>";
return $rets;
}
function webfoot()
{
$rets = "</body></html>";
return $rets;
}
?>
index.php
<?php
include("core.php");
if($mime== WAP)
{
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"". " \"http://www.wapforum.org/DTD/wml_1.1.xml\">";
}else{
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
}
if($mime== WAP)
{
echo waphead($pgtitle,$uid);
echo "<p align=\"center\">";
echo "<img src=\"../themes/".$themedir."/images/logo.png\" alt=\"$pgtitle\"/>";
echo "</p>";
echo wapfoot();
}else{
echo webhead($pgtitle,$uid);
echo "<p align=\"center\">";
echo "<img src=\"../themes/".$themedir."/images/logo.png\" alt=\"$pgtitle\"/>";
echo "</p>";
echo webfoot();
}
?>
The very last script is not effective like others. The best way to join few styles in one is by putting everything in class. Then scripts works quite faster and using it is very simple, while the last script need to check every time if it is wml or xhtml. Instead of checking it in index.php, do it once in a class and everything will be simple External image (may be gone)
The very last script is not effective like others. The best way to join few styles in one is by putting everything in class. Then scripts works quite faster and using it is very simple, while the last script need to check every time if it is wml or xhtml. Instead of checking it in index.php, do it once in a class and everything will be simple External image (may be gone)
true but the script is simple and very easy to understand
hmm it works for me wizard codeing best i had a blank page first ask link7rx to help him couldnt thats why me so happy i did what cant External image (may be gone)
Why is'it lavalair here i don't request that! I wanna to create a simple page where to be WML and XHTML and blackhowk resolved me
<?php
if(!isset($_GET['case'])) $_GET['case'] = '';
switch($_GET['case']) {
case '';
echo "<a href=\"$PHP_SELF?case=1\">wml page</a>
";
echo "<a href=\"$PHP_SELF?case=2\">xhtml page</a>
";
break;
case '1':
header("Content-type: text/vnd.wap.wml;");
echo '<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd">';
echo '<wml>
<head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>
<card id="cipssy" title="HomePage">
<p align="left">
';
echo "<a href=\"java.php?case=1\">Java</a>
";
print '</p></card></wml>';
break;
case '2':
header("Content-type: text/html; charset=ISO-8859-1");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
echo "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\"\"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">\n";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
echo "<head>\n";
echo "<title>HomePage</title>";
echo "</head>\n";
echo "<body bgcolor=\"white\" link=\"#008000\" fontcolor=\"yellow\" vlink=\"#0000CC\" alink=\"#0000CC\">";
echo "<left>";
echo "<a href=\"java.php?case=2\">Java</a>
";
print '</body></html>';
break;
case '3':
echo "Any page format :P";
}
?>
so i still found it lol and now its much better External image (may be gone) External image (may be gone)
i see more modes about this. a. if you use GLOBALS ON your script have serious problem with security - and if my shitty host dont support ON? b. if you use huge clases maybe your server dont parse well this -and whay you use classes if you maybe dont know how its made? c. one simple switch wml 2 xhtml or xhtml 2 wml solve the problem.
as i says: wich script is more lite, easy to use and allow the editor to create compact features?whay should i use this class or core or more inutils functions ( wich i dont know what is ) in one new site or new script?