Crimson Cardinal

Crimson Cardinal's News
  • Home
    Home This is where you can find all the blog posts throughout the site.
  • Categories
    Categories Displays a list of categories from this blog.
  • Tags
    Tags Displays a list of tags that has been used in the blog.
  • Bloggers
    Bloggers Search for your favorite blogger from this site.
  • Login

Adding a Calendar Event to Outlook or iCal

Posted by on in Technology
  • Font size: Larger Smaller
  • Hits: 1923
  • Subscribe to this entry
  • Print

Looking to add the ability to create Calendar events to your website? I wrote up a quick php script that will allow you to do just that. I am not including the form layout, as there are several out there that force a datetime format when the user clicks on the box. Having said that, let's hop right in

First you'll want to specify that the .ics event gets created inline. So you can call this external script without forcing the user to leave their current page

header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=alert.ics");

Next, let's fetch the posted variables from your form. You can create these in separate fields or just call it all at once and split it up on the php side. How you want to do that is really up to you

$year = $_POST['year'];
$month = $_POST['month'];
$day = $_POST['day'];
$time = $_POST['time'] . '00';
$summary = $_POST['summary'];

Next, let's go ahead and build that calendar event folks!

echo "BEGIN:VCALENDAR\n";
echo "VERSION:2.0\n";
echo "PRODID:-//YourSite//NONSGML YourSite//EN\n";
echo "METHOD:PUBLISH\n"; // required by Outlook
echo "BEGIN:VEVENT\n";
echo "UID:".date('Ymd').'T'.date('His')."-".rand()."-yoursite.com\n"; // required by Outlook
echo "DTSTAMP:".date('Ymd').'T'.date('His')."\n"; // required by Outlook
echo "DTSTART:$year"."$month"."$day"."T"."$time\n"; //20120824T093200 (Datetime format required) 
echo "SUMMARY:$summary\n";
echo "DESCRIPTION: this is just a test\n";
echo "END:VEVENT\n";
echo "END:VCALENDAR\n";

And there you have it. Quick, easy and no extra libraries required

0

Comments

Web Applications

Web Application Creation

We are experienced web application developers. Whether you need a desktop application converted to a web application or something simple, we have the right solution for your business.

Web Design

Looking for a unique design to make your website stand out from the crowd? We can create it for you at a reasonable rate!

Search Engine Optimization

Looking to grow your organic search traffic? Want to launch a new paid traffic campaign? We can help you manage your campaigns so you can focus on your business