Jump to content

PHP Web page redirects


sazzie

Recommended Posts

 

I have a php based xhtml webpage which is javascript heavy. Due to the javascript, this webpage will not load in my mobile phone

browser.

 

What I want to achieve is to use the same webpage but direct the mobile phone browser to a function in my php script which will

provided beter suited output for a mobile browser.

Also I would need differently designed scripts for explorer and firefox.

 

Can someone please advise me on how to achieve this desire effect?

Link to comment
Share on other sites

You use the media tag

 

<link rel="stylesheet" type="text/css" href="/common.css" media="screen, print, projection, handheld" />

<link rel="stylesheet" type="text/css" href="/screen.css" media="screen, projection" />

<link rel="stylesheet" type="text/css" href="/print.css" media="print" />

<link rel="stylesheet" type="text/css" href="/handheld.css" media="handheld" />

Link to comment
Share on other sites

You use the media tag

 

<link rel="stylesheet" type="text/css" href="/common.css" media="screen, print, projection, handheld" />

<link rel="stylesheet" type="text/css" href="/screen.css" media="screen, projection" />

<link rel="stylesheet" type="text/css" href="/print.css" media="print" />

<link rel="stylesheet" type="text/css" href="/handheld.css" media="handheld" />

 

Know any good tutorials on this Josi...?  :)

Link to comment
Share on other sites

but are you wondering on how to detect if the browser is a mobile phone?

 

Exactly right!

 

If I can detect what kind of browser is connecting I can choose what it "sees".

 

Unfortunatley that is 'little' tougher.  If you use, as I do, Jesi's method of providing style sheets for different devices then the connecting device picks the one it should use all by itself.

 

There are how ever a couple of exceptions to this which I can't remeber the specifics of; but an example is that one of Nokias devices will always choose the 'screen' type even though it should go for the handheld......

 

You could check the browser details using get_browser() or maybe even the OS by using posix_uname() and echo out the corresponding style sheet based on some logic.  That however would entail you loading your page on a range of devices and seeing what the output is inorder to construct that logic; unless there is a page somewhere (sure there will be) that lists all the major devices and their browser or OS details.

 

I go with the method described by Jesi and don't care about people who buy devices that don't conform to the recommendations provided by W3C.

Link to comment
Share on other sites

One thing some places do is have a mobile subdomain, such as m.mysite.com - anyone on a handheld should go there - and then for that subdomain you force a different CSS instead of letting the device pick. I like that idea as well.

Link to comment
Share on other sites

One thing some places do is have a mobile subdomain, such as m.mysite.com - anyone on a handheld should go there - and then for that subdomain you force a different CSS instead of letting the device pick. I like that idea as well.

 

Pretty Cool "JESI"  ;)

Link to comment
Share on other sites

One thing some places do is have a mobile subdomain, such as m.mysite.com - anyone on a handheld should go there - and then for that subdomain you force a different CSS instead of letting the device pick. I like that idea as well.

 

There is one reason I don't like that approach - it means twice as much work keeping your site current. 'One site fits all' is my favorite motto....

 

The only benefit in providing a purely free mobile zone is if you have produced WML pages...

Link to comment
Share on other sites

One thing some places do is have a mobile subdomain, such as m.mysite.com - anyone on a handheld should go there - and then for that subdomain you force a different CSS instead of letting the device pick. I like that idea as well.

 

There is one reason I don't like that approach - it means twice as much work keeping your site current. 'One site fits all' is my favorite motto....

 

The only benefit in providing a purely free mobile zone is if you have produced WML pages...

 

Buddy, you've lost me back there  ???

Link to comment
Share on other sites

If you wanted a TOTALLY different page... you could use the browsers user agent string to work out which browser/device/version is accessing your page and use a location header to redirect the a different page/domain etc.

 

Personally I think thats a crap way of doing it but its a choice :)

 

I think the CSS method is good, or theres always XSLT...

Link to comment
Share on other sites

If you wanted a TOTALLY different page... you could use the browsers user agent string to work out which browser/device/version is accessing your page and use a location header to redirect the a different page/domain etc.

 

Personally I think thats a crap way of doing it but its a choice :)

 

I think the CSS method is good, or theres always XSLT...

 

Do you have sample code for the browser user agent?

Link to comment
Share on other sites

Just add whatever browsers you want to look for int the $browsers array...

 

$useragent = $_SERVER['HTTP_USER_AGENT'];
$browser = get_browser_name($useragent);

print ("Browser name: ".$browser['browser']."<br />Browser version: ".$browser['version']."<br />");

function get_browser_name($useragent){
  $browser = array (
    "Opera","Msie", "Netscape", "Firefox","Safari", "Konqueror", "Mozilla"
  );
  $info["browser"] = "Other";
  foreach ($browser as $parent) {
   if ( ($s = strpos(strtolower($useragent), strtolower($parent))) !== FALSE )   {
     $f = $s + strlen($parent);
     $version = substr($useragent, $f, 5);
     $version = preg_replace('/[^0-9,.]/','',$version);
     $info["browser"] = $parent;
     $info["version"] = $version;
     break; // first match wins
   }
  }
  return $info;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.