Timetable

Tuesday, February 19, 2008 by Nasir

Yesterday is was at work very little to do and at times like that I start writing small software to kill time and polish my skills.

I am writing an application that should run on my phone. I want it to fetch my university timetable and show it as today plug-in for Windows Mobile phone, but I can’t do that while working. That is why I developed a web page that would fetch my timetable from the university web page. That page is a from and you have to preform a couple steps before you got to see what your class timetable is.

I used PHP for this task, but I could not write it like I always do that. Normally I use fopen() and read and write to it, but this hosting turned allow_url_fopen directive off. After looking around in phpinfo() I found that PHP is compiled with option -–with-curl. I have never worked with cURL before, but it is so easy to use.

It is all about this code:

	
$url = "http://www.example.com/form.html";
	
$postFields = "field_id=8823&week=" . $monday . "&Submit=Send";
	
$ch = curl_init();
	
curl_setopt($ch, CURLOPT_URL,$url);
	
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
	
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
	
curl_setopt($ch, CURLOPT_POST, 1);
	
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
	
$result = curl_exec($ch);
	
curl_close($ch);
	

What I have done is send HTTP POST to the web server with the values it needs. So in your case you only need to change the $url and $postFields variables.