NWS Weather Forecast Messenger PHP Script by Mike Challis
More Info        - www.642weather.com/weather/scripts-nws-forecast-messenger.php
Download         - www.642weather.com/weather/scripts/nws-forecast-messenger.zip
Live Demo        - www.642weather.com/weather/nws-forecast-messenger.php
Free PHP Scripts - www.642weather.com/weather/scripts.php
Contact Mike     - www.642weather.com/weather/contact_us.php
Donate:          https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2319642  

Version: 2.01 - 29-Sep-2011 - release  see changelog.txt for changes

Support thread at weather-watch forum:
http://www.weather-watch.com/smf/index.php/topic,40830.0.html

You are free to use and modify the code

Partially based on a variation of the following scripts:
NOAA Top Weather Advisory Alerter PHP Script by Mike Challis
http://www.642weather.com/weather/scripts-noaa-top-weather-alerter.php
RSS Top Warning PHP Script by Ken True http://saratoga-weather.org/scripts.php
PHP NOAA Advisory Text by Tom Chaplin http://www.carterlake.org/weatherphp.php
Twitter Code by http://morethanseven.net/2007/01/20/posting-to-twitter-using-php/
Forecast code based on http://jivebay.com/2008/04/08/free-weather-forecast/

This php code provided "as is", and Long Beach Weather (Michael Challis)
disclaims any and all warranties, whether express or implied, including
(without limitation) any implied warranties of merchantability or
fitness for a particular purpose.


################
# What does it do?
# ##############

Ever want to receive weather forecasts by cell phone, blackberry, Facebook, Twitter, or email? Now you can. 

This PHP script is used to check the NOAA Weather XML Forecast feeds on a timed schedule,
then send a forecast message.
Uses the forecast for the the latitude longitude you have set in the settings.
The forecast message is short enough to send to a cell phone, blackberry, Facebook, Twitter, or email.
Each message method can be enabled or disabled.
Messages can be customized in the script settings.


################
# What do I need?
# ##############

PHP 5 with CURL support is required
.. Web server hosting account with PHP support and ability to send emails from PHP
.. Ability to schedule a cron job or a scheduler program on your PC that can request a URL every x hours.
.. Your PHP server MUST allow PHP scripts permission to write files.
.. PHP safe_mode is recommended to be off

################
# How to use it:
# ##############

1) Set your settings in the "settings" of the nws-forecast-messenger.php PHP script.
Be sure to set the latitude, longitude, twitter user/password and your email address.
Also set the settings to customize the messages for Email and Twitter. 
Each method (email, twitter) can be enabled or disabled.

2) Upload the nws-forecast-messenger.php PHP file to your web server

3) Test from a URL, see if you can see the HTML output:
Example: http://www.yoursite.com/nws-forecast-messenger.php

4) It is recommended that you test an email/twitter to make sure the script is working.
   Enable the email or twitter setting. 
   Click the URL, example: http://www.yoursite.com/nws-forecast-messenger.php
   Check if you receive your message or not.

5) After testing if you receive your message or not, 
   you need to secure the script because you do not want people clicking the URL and flooding you with emails and twitters!
   There are 3 ways to secure it... make sure you do this step, don't just "set it and forget it":

   Method 1) (recommended) Use the setting $require_post to require post authentication to send messages.
             This method will allow the script to be clicked on, but it will only send the messages on your schedule.

   Method 2) Use the setting $flood_filter_enabled.
             This method will allow the script to be clicked on, but it will only send the messages on your schedule.

   Method 3) Move it to a private non-public web server folder, then the only way you can call it is from a cron job.
         

6) Schedule automatic timed message sending: 
There are a few ways to do this, I use method 1 but not every web host allows it.
Log into your web server control panel, find the "cron" settings.
Wiki page for cron: http://en.wikipedia.org/wiki/Cron
Schedule a server cron job to run this PHP file every 12 hours. The following methods correspond to the method you select in step 5 above.

Method 1: (recommended)
Example using cron and CURL with post authentication: (be sure to set 'your_username' and 'your_password' same as in PHP script settings)
00 06,18 * * * /usr/bin/curl -d 'username=your_username&password=your_password' http://www.642weather.com/weather/nws-forecast-messenger.php >/dev/null 2>&1 

Method 2:
Example using cron and CURL:
00 06,18 * * * /usr/bin/curl http://www.642weather.com/weather/nws-forecast-messenger.php >/dev/null 2>&1

Method 3:
Example using cron and PHP: (change '/path/to/' to your server path)
00 06,18 * * * php /path/to/nws-forecast-messenger.php 2>&1 > /dev/null

Method 4: 
Use Windows Task Scheduler and a Scheduled HTTP Request 
to the URL http://www.yourwebsite.com/nws-forecast-messenger.php every x hours
Instructions here:
http://www.642weather.com/weather/wxblog/php-scripts/scheduled-http-request-windows-task-scheduler/

Note:
Some users have file permissions problems with the cache files:
Here are some tips: (Do this only if you are having file permissions errors!)
Create the file in Notepad or similar text editor. The file can be empty. 
nws-forecast-messenger.txt
nws-forecast-messenger-flood.txt
Upload it to your server and CHMOD it to 666
You may continue to have problems if your server has "safe_mode on" or other restrictions on file create, file write functions.
In that case, please consult your web host tech support.


Twitter usage:
See readme.txt inside TweetWX642 folder


###########################################
How to send these messages to Facebook: 
(Requires a Facebook and a Twitter account) 
###########################################
Log into Facebook and go to this app:
http://www.facebook.com/selectivetwitter
Click settings and add your Twitter username, then grant permissions.
End a tweet with #fb when you want it to update your Facebook status - simple.

I made a Facebook page for 642weather, then made a personal profile for myself, I am the admin of the page now.
Pages and profiles are two different things.


-----------------------------------------
Live Example
-----------------------------------------
You can see my script in use here: (it will not email you though, because it only emails me.)
http://www.642weather.com/weather/nws-forecast-messenger.php 
http://www.twitter.com/642weather
http://www.facebook.com/profile.php?id=102474670891

-----------------------------------------
Donate
-----------------------------------------
A paypal donate button is on my scripts page
www.642weather.com.com/weather/scripts.php
or use this direct link:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2319642


