2uzhan.com
Advertisement
Now Place:2uzhan.com » Need to convert ASP code for redirect to PHP!

Need to convert ASP code for redirect to PHP!

PHP @ February 11, 2003   Views:0

Hi,

Well as I can see this is a wonderful site on PHP! Terrific. Need some help. I have to be able to redirect to either an index.php page or an index.wml page depending if the user is using a browser or a wap enabled device. I have some ASP code that does the job however ASP is not supported my host. Basically what I need to do is the exact same thing the ASP code is doing below:

<%
if InStr(Request.ServerVariables("HTTP_ACCEPT"), "wml") then
Response.Redirect("index.wml")
else
Response.Redirect("index.php")
end if
%>

How can I achieve the above with PHP? HElp.... Thank you

--------------Solutions-------------

Probably stristr will do it for ya ...

PHP Code:

<?php
if (stristr($_SERVER['HTTP_ACCEPT'], "wml")) {
      header("location: index.wml")
} else {
      header("location: index.php")
}
?>

HTH,

Looks good I will give it a try and let you know.
Would I have to put the above code into the index.php file or would I have to create a new index.php file including just the code above and rename my existing index.php file to another name that can be refrenced from the code above?

I will keep you posted thanks.....

(Jeeze you guys are quick.!!!).

I assume your server default to showing 'index.php'? It does seem you've grasped the problem....

If so, you should be able to put this code in your extant index.php file, with the exception of the fact that doing so in exactly this form will just stick you in an endless loop. [!!] Instead, omit the code section that starts with the "else" and then put this code into index.php....

Note that to use header(), you must not allow any output to the browser (including any whitespace) prior to the header() call. So, just make sure that the code is above any calls to echo, print, or escaped HTML, and that there's no whitespace in between your PHP tags above the code.

Well I had a better understanding of how we can redirect however when adding the code above to my index.php file as follows:

<?php

// This is a web statistics Analyzer //

require("WebAnalyze/include/stats_main.inc");
$stats = new init(true, 'WebAnalyze/'); // 2 params. true/false to activate or not.

if (stristr($_SERVER['HTTP_ACCEPT'], "wml")) {
header("location:/Mobile/Documents/Index.wml")
}

} else {

include 'infiniteBuilder.php';

echo $top;

echo $home;

echo $bottom;

?>

I get a blank page when accessing with IE. I also get "No Content" when accessing with my Wap enabled device.

I'm I forgetting something here?

Thanks for the quick replies.

Well, you didn't close your else, so it's possible that the server is logging a parse error instead of showing it to stdout (which is the browser, in this case...)

You don't actually need the } else { line anyway; if the script sees "wml" in the ACCEPT variable, it'd take the user to a new location anyway, and will continue execution if it doesn't, therefore that line's unnecessary.

Not knowing the nature nor content of the *.inc file and the init() class, I can't say for sure what else is happening.

You might grep your httpd-error.log for messages, though.

HTH,

Hi

Well ok I let me start by saying the int and the init() class are related to a Web log analyzer I have set up for the actual php website. Which works really well. So does the entire Php site.

I did some research and yes HTTP_ACCEPT should retrieve the appropriate information then we can stristr the info through to select with index page.

Not that I doubt the intergrity of your code. You should be on the money.

Problem -- After removing everything and just simply creating an index.wml and an index.php page and including your code. Still getting a blank page.

-- Adding the code without the else. Still a blank page. Doing a view source I only see the browser info. Nothing else. Trying on the cell phone gives me "No content"

I went even further. I looked everywhere for info. There are ASP, and other multiple methods however i want it in PHP. Everything points to the HTTP_ACCEPT method.

Stuck between a rock and a hard place. Thanks for replying I just hope I can solve this redirecting problem (no let me rephrase that I will somehoe solve this redirect problem.)

<?php

// This is a web statistics Analyzer //

require("WebAnalyze/include/stats_main.inc");
$stats = new init(true, 'WebAnalyze/'); // 2 params. true/false to activate or not.

if (stristr($_SERVER['HTTP_ACCEPT'], "wml")) {
header("location:/Mobile/Documents/Index.wml")
} This is closing your if statement. The else is no longer related. So remove this bracket

} else {

include 'infiniteBuilder.php';

echo $top;

echo $home;

echo $bottom;
close the else statement here by adding a close bracket
?>

For starters the above code just won't work. Even if I code a simple index.html and a simple index.wml on seperate pages to use the else. I checked the syntax with minor adjustment. Won't work.

After hours and hours of research I came across an interesting snipet of code. ===

HELP
Wireless services and WAP Return to Help menu

Introduction to WAP
Introduction to WML
Introduction to XML
Reasons to use WML
Viewing WAP sites without a wireless device
WAP and domain names
WAP file extensions
WML file location
WML file permissions
WAP images
More information about WAP, WML and XML

--------------------------------------------------------------------------------

Introduction to WAP

WAP stands for Wireless Application Protocol, although in reality WAP is a collection of protocols and specifications. The purpose of this standard is to serve information and services on the Internet to wireless clients and WAP devices, such as mobile phones and terminals. The authoritative source for WAP is www.wapforum.org.

Top of Page

Introduction to WML

WML (Wireless Markup Language) is a markup language based on XML. Technically it is an XML application. Just like HTML and XML, WML is read and interpreted by a browser built into the WAP device. For WAP devices, the browser is commonly called a micro browser, indicating that its capabilities are somewhat limited. Additional limitations may be the result of the device that the micro browser runs on. If you have no prior knowledge of XML, you will probably find WML much more stringent than HTML.

WML files are referred to as "decks". Each deck consists of one or more cards. Cards begin and end with <card> tags, while decks begin and end with <deck> tags. When the WML micro browser accesses a WML document (or deck), it reads the whole deck. Therefore, it doesn't need to load any more data to navigate between cards. The <card> tag in WML is very similar to the <a name> tag of HTML.

WAP devices have very little memory, so there is a limit to how big each WML deck can be. The limit varies a great deal from one browser to another. These limits refer to the compiled form of your deck, which is usually fairly small compared to the plain text XML code that you send out from the server.

Example:

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1" title="Card 1">
<p>
Hello World!
</p>
</card>
<card id="card2" title="Card 2">
<p>
Hello World!
</p>
</card>
</wml>

Top of Page

Introduction to XML

The Extensible Markup Language (XML) is a subset of SGML that was designed especially for Web documents. It allows the creation of customized tags, and it enables the transmission and interpretation of data between applications and between organizations.

Top of Page

Reasons to use WML

WML is used in the WAP environment instead of HTML. WML is designed for wireless devices. Compared to HTML, WML requires very little bandwidth and much less processing strength to render, which means longer lasting batteries. Finally, HTML requires a larger display than is available on a mobile phone.

Top of Page

Viewing WAP sites without a wireless device

WML can be read by any micro browser and a variety of emulators. Some of them require installation of components such as Java Runtime. You should test with more than one of these tools, and verify that you are using an emulator that accurately simulates the devices you are ultimately targeting.

Top of Page

WAP and domain names

It is very practical to re-use already existing HTML code, so it can be beneficial to have your first page (homepage) differentiate between a desktop HTML browser and a mobile WML browser and serve content accordingly. This allows the same URL (yourname.com) to be used to view both your HTML site and your WAP site.

The PHP code below allows you to do just that. Implement this code into an INDEX.PHP page, before any of your site content is loaded. It will first attempt to identify what type of browser is trying to hit your site. If the PHP code identifies a WAP user from the list of possible WAP browsers, it will direct the user (seamlessly) to the specified WML pages. If it does not identify a WAP browser or any browser at all, it will redirect to your specified HTML page.

Advanced Implementation: This has to be done on the server side, and the following PHP code will first attempt to discover if the WAP gateway being used can accept the text/vnd.wap.vml MIME type. If not, it will check the first four characters in the ID string to determine if it's a WML browser. If there's no match, it's assumed that it's an HTML browser. As new WML browsers come along, their ID strings should be added to the list.

The code is based on Robert Whitinger's ([email protected]) code submitted to the PHP mailing list, with several additions for browser ID string from Don Amaro's ([email protected]) log files.

Example code:

<?
// Because this script sends out HTTP header information,
// the first characters in the file must be the <? PHP tag.
$htmlredirect = "/html/my_htmlpage.html"; // relative URL to your HTML file
$wmlredirect = "http://wap.mysite.com/wml/my_wmldeck.wml"; // ABSOLUTE URL to your WML file
if(strpos(strtoupper($HTTP_ACCEPT),"VND.WAP.WML") > 0) { // Check whether the browser/gateway
$br = "WML"; // says it accepts WML.
}
else {
$browser=substr(trim($HTTP_USER_AGENT),0,4);
if($browser=="Noki" || // Nokia phones and emulators
$browser=="Eric" || // Ericsson WAP phones and emulators
$browser=="WapI" || // Ericsson WapIDE 2.0
$browser=="MC21" || // Ericsson MC218
$browser=="AUR " || // Ericsson R320
$browser=="R380" || // Ericsson R380
$browser=="UP.B" || // UP.Browser
$browser=="WinW" || // WinWAP browser
$browser=="UPG1" || // UP.SDK 4.0
$browser=="upsi" || // another kind of UP.Browser ??
$browser=="QWAP" || // unknown QWAPPER browser
$browser=="Jigs" || // unknown JigSaw browser
$browser=="Java" || // unknown Java based browser
$browser=="Alca" || // unknown Alcatel-BE3 browser (UP based?)
$browser=="MITS" || // unknown Mitsubishi browser
$browser=="MOT-" || // unknown browser (UP based?)
$browser=="My S" || // unknown Ericsson devkit browser ?
$browser=="WAPJ" || // Virtual WAPJAG www.wapjag.de
$browser=="fetc" || // fetchpage.cgi Perl script from www.wapcab.de
$browser=="ALAV" || // yet another unknown UP based browser ?
$browser=="Wapa") // another unknown browser (Web based "Wapalyzer"?)
{
$br = "WML";
}
else {
$br = "HTML";
}
}
if($br == "WML") {
header("302 Moved Temporarily"); // Force the browser to load the WML file instead
header("Location: ".$wmlredirect);
exit;
}
else {
header("302 Moved Temporarily"); // Force the browser to load the HTML file instead
header("Location: ".$htmlredirect);
exit;
}
?>

====

Now you will all say WOW. However from what I gather (and I spent 6 grewling hours on this.) there has to be multiple phone ID's ect... After implementing the above code. I STILL GET A BLANK PHP index and the phone sends back a INTERNET 500 Error. At least its a bit better than nothing.

This is starting to look like a million dollar question. It seems everyone is trying to figure out how to do this.

I'll keep everyon posted. If anyone has anybetter ideas or would like actual code I am using let me know I'll gladly supply it.

Thanks for all your amazing help and if I find a solution I will post it here so at least some other fella doesn't bump into the same problem.

Thank you everyone for your help.
The above code works.

---- You guys have me. Let me tell you this is the best web site on the planet for PHP.

Way to go.

Tags:
© 2018 2uzhan.com Contact