Username:
Password:

Web - Generate a dynamic ical calendar in PHP

Creation: 24/07/2009 19:35

Last Modification: 24/07/2009 19:35

Sometimes when you publish a list of events at specific dates on your website,
it can be usefull to allow external people to subscribe to a calendar using outlook
or any other calendar (mozilla calendar or ical for example).

To do this you can create a php webpage creating an ical compatible file dynamically.

1- Generate informations in php:

Create the ical header:

print("BEGIN:VCALENDAR\n");
print("VERSION:2.0\n");
print("PRODID:-//hacksw/handcal//NONSGML v1.0//EN\n");


Then you need to create events, here i add an event on the first of July 2010 at
9 o'clock PM to 11 o'clock PM named "come to my party":

print("BEGIN:VEVENT\n");
print("DTSTART:20100701T210000\n");
print("DTEND:20100701T230000\n");
print("SUMMARY:come to my party\n");
print("END:VEVENT\n");


You can generate those entries from any inputs, like an sql database for example.
Lots of other flags are available in the vcalendar format if you want to create
something more complex.

At the end you must finish the calendar using:

print('END:VCALENDAR\n");


Now you just need to tell people to add a network calendar and to enter
the address of the php page you created.