Author Topic: redirect script  (Read 14344 times)

0 Members and 1 Guest are viewing this topic.

Offline weathergirl

  • Forecaster
  • *****
  • Posts: 677
    • Beamsville Weather Station
redirect script
« on: August 18, 2010, 09:21:44 AM »
Is there a script I can use that can direct visitors browsing for my site on their cell phones to my cellphone or iPhone pages instead of my regular website?
Ann-Marie
Beamsville, Ontario, Canada

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2296
    • CNYWeather
Re: redirect script
« Reply #1 on: August 18, 2010, 11:56:54 AM »
Here Ann-Marie. I got mine here:

http://detectmobilebrowsers.mobi/

This is what I have in top of my index page from it:

I generated a mobile_device_detect.php file from the site above. Pretty easy.
then put the generated file in my index:

Code: [Select]
############################################################################
# This document uses Tab 4 Settings
############################################################################
require_once("Settings.php");
require_once("common.php");
require_once('mobile_device_detect.php');
mobile_device_detect(false,false,false,true,true,true,true,true,'http://www.cnyweather.com/cell.php?skip=1');

the false, false, false, true etc was generated for different devices from that site.

Go to my home page on a mobile device and you'll get shuffled over to the mobile site.
I'm in the process of giving it it's own subdomain  m.cnyweather.com and havent finished it as of yet.


Tony  8-)
« Last Edit: August 18, 2010, 11:59:14 AM by CNYWeather »
Tony




Offline weathergirl

  • Forecaster
  • *****
  • Posts: 677
    • Beamsville Weather Station
Re: redirect script
« Reply #2 on: August 18, 2010, 12:02:26 PM »
Excellent, thanks Tony :)
Ann-Marie
Beamsville, Ontario, Canada

Offline dasman

  • Forecaster
  • *****
  • Posts: 491
    • Wx Peotone
Re: redirect script
« Reply #3 on: August 18, 2010, 12:41:42 PM »
Where do you put the generated file on the index page?
Dave Sommerfed
Peotone Illinois USA
CW7762, KILPEOT1
NWS COOP, CoCoRaHS, Spotter Network

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2296
    • CNYWeather
Re: redirect script
« Reply #4 on: August 18, 2010, 12:46:08 PM »
I'm using the ajax-dashboard.php for my site. I just put it up before the main code.

I'd say before your main-content on your site?
Tony




Offline dasman

  • Forecaster
  • *****
  • Posts: 491
    • Wx Peotone
Re: redirect script
« Reply #5 on: August 18, 2010, 01:06:15 PM »
Well I'm missing something...  Here is the generated code:

require_once('mobile_device_detect.php');
mobile_device_detect

(true,false,true,true,true,true,true,'http://mobile.peotoneweather.com',false);

Here is how I included it:

<?php

require_once('mobile_device_detect.php');
mobile_device_detect

(true,false,true,true,true,true,true,'http://mobile.peotoneweather.com',false);
?>

And here is the error I get when I try to access from a cell phone (note...Still works on a PC):

Warning: Cannot modify header information- headers sent by (output started at
/home/content/p/e/o/peotone/html/index.php:3) in
/home/content/p/e/o/peotone/html/mobile_device_detect.php on line 165

Ive tried the code in the body and in the head and before the head!
Dave Sommerfed
Peotone Illinois USA
CW7762, KILPEOT1
NWS COOP, CoCoRaHS, Spotter Network

Offline dasman

  • Forecaster
  • *****
  • Posts: 491
    • Wx Peotone
Re: redirect script
« Reply #6 on: August 18, 2010, 01:17:28 PM »
Quote
Go to my home page on a mobile device and you'll get shuffled over to the mobile site.

I tried your site from my Iphone, and I was not redirected!  I got your normal Index Page!

Do you have IPhones set to not redirect?
Dave Sommerfed
Peotone Illinois USA
CW7762, KILPEOT1
NWS COOP, CoCoRaHS, Spotter Network

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2296
    • CNYWeather
Re: redirect script
« Reply #7 on: August 18, 2010, 01:27:24 PM »
Yeah IPhone, Ipod Touch dont redirect. Someone complained that they like my normal site.
I'm gonna chance it in a sec so you can see.

Did you upload the mobile_device_detect.php to your root directory?
Tony




Offline dasman

  • Forecaster
  • *****
  • Posts: 491
    • Wx Peotone
Re: redirect script
« Reply #8 on: August 18, 2010, 01:30:33 PM »
yes its in the root!  There are no settings in it are there?
Dave Sommerfed
Peotone Illinois USA
CW7762, KILPEOT1
NWS COOP, CoCoRaHS, Spotter Network

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2296
    • CNYWeather
Re: redirect script
« Reply #9 on: August 18, 2010, 01:34:19 PM »
I think maybe it's the false at the end of the statement?

change
Code: [Select]
(true,false,true,true,true,true,true,'http://mobile.peotoneweather.com',false);

to
Code: [Select]
(true,false,true,true,true,true,true,false,'http://mobile.peotoneweather.com',);

So the redirect url is last.  SRY, i've got 100 trophies to build. I'll check back later.
Tony




Offline dasman

  • Forecaster
  • *****
  • Posts: 491
    • Wx Peotone
Re: redirect script
« Reply #10 on: August 18, 2010, 01:40:44 PM »
I tried it , but then the website didn't show on PC's or cells!  Ill  tinker with it.
Dave Sommerfed
Peotone Illinois USA
CW7762, KILPEOT1
NWS COOP, CoCoRaHS, Spotter Network

Offline dasman

  • Forecaster
  • *****
  • Posts: 491
    • Wx Peotone
Re: redirect script
« Reply #11 on: August 18, 2010, 04:01:32 PM »
On the redirect site in the trouble shooting i found the error message that shows "only" when you try to view my page from a mobile device:

Quote
Problem
An error like Warning: Cannot modify header information - headers already sent by.... tells you that the script making the call to the function is doing something before it should!

Solution
You need to 3 the file with the function and make the function call before your script does anything else!

This error is caused when the script creates output like text, markup or plain white space before it sets any headers. Removing any whitespace and ensuring this function is called first will solve this.



I have no idea what  "You need to 3 the file with the function and make the function call before your script does anything else!" even means.

Any help from anyone would be appreciated!
Dave Sommerfed
Peotone Illinois USA
CW7762, KILPEOT1
NWS COOP, CoCoRaHS, Spotter Network

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2296
    • CNYWeather
Re: redirect script
« Reply #12 on: August 18, 2010, 05:08:42 PM »
Sorry.

Maybe one of the wizards will chime in. I dont know what that means.
Tony




Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2296
    • CNYWeather
Re: redirect script
« Reply #13 on: August 18, 2010, 08:09:30 PM »
Dave, clicking on mobile.peotoneweather.com says I need a Google Maps API key now.
Tony




Offline dasman

  • Forecaster
  • *****
  • Posts: 491
    • Wx Peotone
Re: redirect script
« Reply #14 on: August 18, 2010, 08:35:01 PM »
I'm not sure why?  I don't have a key on the page or a google map.  Actually mobile.peotoneweather.com is an empty folder on the server redirected to peotoneweather.com/mobile.php  And like I said no map or key!


I do however have a key on the index page?   I'm so confused. ](*,)


I have removed the API key from the index page.  You should now be able to go to  mobile.peotoneweather.com and get redirected to peotoneweather.com/mobile.php.

However I have made no progress on the script.  I still get the error message when I try to access the website from a mobile device!

I'm in need of a code guru to help me figure out the error messages a few posts above this one.
« Last Edit: August 18, 2010, 09:23:12 PM by dasman »
Dave Sommerfed
Peotone Illinois USA
CW7762, KILPEOT1
NWS COOP, CoCoRaHS, Spotter Network

Offline W Thomas

  • Welcome to my area!
  • Forecaster
  • *****
  • Posts: 1647
  • In Loving Memory Of Hooker The Weather Dog !
    • Smyth-Grayson Weather
Re: redirect script
« Reply #15 on: August 18, 2010, 11:41:26 PM »
This thread has some good information     http://www.wxforum.net/index.php?topic=6118.0

I haven't gotten around to making a WD version of a mobile page yet so I am directing the lower resolution devices to my WU mobile page.
Not exactly how I want to leave it but it sort of works in a pinch :-)
« Last Edit: August 22, 2010, 01:45:32 PM by W Thomas »


     Best Regards
     Wayne

CWOP CW8217
KVAWHITE22 Wunderground   Davis VUE &  Davis Vantage Pro 2  /   Dedicated Server
GR Level 3 ,Level 2 AE Radars  Weather Display 10.37P  Mid Atlantic Weather Network Member
SkyWarn & Spotter Network 6092

Offline ELDoradoWx

  • El Dorado Weather
  • Senior Contributor
  • ****
  • Posts: 298
  • Gentoo X = Complete_Control
    • El Dorado Weather
Re: redirect script
« Reply #16 on: August 19, 2010, 01:56:41 AM »
Well I'm missing something...  Here is the generated code:

require_once('mobile_device_detect.php');
mobile_device_detect

(true,false,true,true,true,true,true,'http://mobile.peotoneweather.com',false);

Here is how I included it:

<?php

require_once('mobile_device_detect.php');
mobile_device_detect

(true,false,true,true,true,true,true,'http://mobile.peotoneweather.com',false);
?>

And here is the error I get when I try to access from a cell phone (note...Still works on a PC):

Warning: Cannot modify header information- headers sent by (output started at
/home/content/p/e/o/peotone/html/index.php:3) in
/home/content/p/e/o/peotone/html/mobile_device_detect.php on line 165

Ive tried the code in the body and in the head and before the head!

Hi Dave,

Two things you could check IF you are still having this problem.

Make sure you don't have any improper white space in your php include script between the opening and closing tags "<?php" and "?>"...

On your example above you have spread out the script with white space that is most likely causing or contributing to your header error.

Try it like this:
Code: [Select]
<?php require_once('mobile_device_detect.php'); 
mobile_device_detect(true,false,true,true,true,true,true,'http://mobile.peotoneweather.com',false); ?>

Also, make sure the php include function is called first on your web page before anything else is called (including any white space  :grin: ).

Doing a double redirect is interesting, but I think you can get away with it.
« Last Edit: August 19, 2010, 03:04:00 AM by ELDoradoWx »
-Danny
-root is everything

Offline dasman

  • Forecaster
  • *****
  • Posts: 491
    • Wx Peotone
Re: redirect script
« Reply #17 on: August 19, 2010, 07:44:20 AM »
Quote
Try it like this:

Code:
<?php require_once('mobile_device_detect.php');
mobile_device_detect(true,false,true,true,true,true,true,'http://mobile.peotoneweather.com',false); ?>
Also, make sure the php include function is called first on your web page before anything else is called (including any white space   ).

I tried the code as you said and put it at the to top of the page.  Still the same...

Below is the top of my page:

Viewing from PC is still fine!  I get the error when trying from iphone!  Anyone with another mobile device get different results?
www.peotoneweather.com

Quote
<?php require_once('mobile_device_detect.php');
mobile_device_detect(true,false,true,true,true,true,true,'http://mobile.peotoneweather.com',false); ?>
<!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"><!-- InstanceBegin template="../../../peotoneweather/Templates/indextemplate.dwt.php" codeOutsideHTMLIsLocked="false" -->


<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The Sommerfelds</title>
<script src="/SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="/SpryAssets/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
<meta http-equiv="refresh" content="300">
<meta name="Keywords" content=" Peotone , Peotone weather station, weather, David Sommerfeld ">
<meta name="Description" content="Local Weather Conditions Measured Right Here In Peotone IL.  We Also Have Radar And Satellite maps">
<meta name="Abstract" content="David Sommerfeld">
<meta name="Abstract" content="Peotone weather data.">
<meta name="ICBM" content="41.33366776, -87.78903198">
<meta name="DC.title" content="Peotone Weather">
<link rel="stylesheet" type="text/css" href="./WU-HistoryBlue.css" />
<script type="text/javascript" src="ajaxVWS.js"></script>
<style type="text/css">
<!--
body,td,th {
   font-family: Arial, Helvetica, sans-serif;
}
-->
</style>

<script src="ClusterMarker.js" type="text/javascript"></script>
<script src="mapiconmaker.js" type="text/javascript"></script>


<script src="global-conditions-json.php" type="text/javascript"></script>
</head>
« Last Edit: August 19, 2010, 07:46:13 AM by dasman »
Dave Sommerfed
Peotone Illinois USA
CW7762, KILPEOT1
NWS COOP, CoCoRaHS, Spotter Network

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2296
    • CNYWeather
Re: redirect script
« Reply #18 on: August 19, 2010, 02:21:52 PM »
Any luck?  It looks a little suspicious to me being the first thing up there in your code.

I'm sorry, i'm just a code hacker. Are you on the WD Forums? If so, I'd ask in the IPhone discussion.
Tony




Offline DaculaWeather

  • WxElement panel
  • Forecaster
  • *****
  • Posts: 3206
    • North Georgia Weather
Re: redirect script
« Reply #19 on: August 19, 2010, 02:29:24 PM »
One of my concerns for an automatic re-direct is what if someone WANTS to go to the regular site. It seems like I saw something somewhere that took that into consideration.

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2296
    • CNYWeather
Re: redirect script
« Reply #20 on: August 19, 2010, 02:34:01 PM »
Yeah thats my issue. I've had some uses what to go to the regular site instead of
automagically to the mobile one. Haven't figured that out yet.
Tony




Offline dasman

  • Forecaster
  • *****
  • Posts: 491
    • Wx Peotone
Re: redirect script
« Reply #21 on: August 19, 2010, 02:40:09 PM »
I just fixed it! Thanks to Wayne!

Quote
This thread has some good information     http://www.wxforum.net/index.php?topic=6118.0

When I went through the thread I found there was code to add to the php.ini file it is
Quote
output_buffering = On
.

Now mobile browsers are detected and redirected.  And the code is no longer at the very top of the page.  It is now the first thing listed in the body! Now I have to put another page up that mirrors the index page but without the mobile browser php, so I can add a link to the mobile page for them to view a full page!

Can someone with a mobile device other then an iphone go to www.peotoneweather.com and see if you are redirected to my mobile page?
Dave Sommerfed
Peotone Illinois USA
CW7762, KILPEOT1
NWS COOP, CoCoRaHS, Spotter Network

Offline dasman

  • Forecaster
  • *****
  • Posts: 491
    • Wx Peotone
Re: redirect script
« Reply #22 on: August 19, 2010, 02:49:21 PM »
Quote
One of my concerns for an automatic re-direct is what if someone WANTS to go to the regular site. It seems like I saw something somewhere that took that into consideration.

I made a copy of my index page and made it index2.  I removed the "php for mobile browser detection" and uploaded it. Then I put:

Quote
<a href="http://peotoneweather.com/index2.php">View full(non mobile version)

webpage! page</a>

at the bottom of the mobile page!

Now I believe (HOPE) all mobile devices are being detected and redirected to the mobile page.  And if they wish. a link at the bottom of the page will allow them to view the "full page" version.
« Last Edit: August 19, 2010, 07:13:30 PM by dasman »
Dave Sommerfed
Peotone Illinois USA
CW7762, KILPEOT1
NWS COOP, CoCoRaHS, Spotter Network

Offline m77

  • Forecaster
  • *****
  • Posts: 878
Re: redirect script
« Reply #23 on: August 20, 2010, 01:28:10 AM »
I viewed on my nokia E71 and it looks great.  Well done mate!

How did you get the "viewers online " statistic?

edit: just seen the ad name!
« Last Edit: August 20, 2010, 01:33:49 AM by m77 »
Weatherlink ip, Vantage Vue,

Offline DaculaWeather

  • WxElement panel
  • Forecaster
  • *****
  • Posts: 3206
    • North Georgia Weather
Re: redirect script
« Reply #24 on: August 20, 2010, 06:49:57 PM »
Works on my HTC Google phone, can someone with a phone try going to my main page at http://www.daculaweather.com and see if you get redirected? Please!  :-)

Thanks!

 

anything