Please feel free to browse the site and get in touch if you have any questions...  

Do you require an online store?  

 

Evilprofessor Designs the home of affordable web site design
Quick inexpensive open source websites through to full bespoke web applications...

Evilprofessor Designs

Here at Evilprofessor Designs we encourage the research into new technologies and learn how to use them in new and interesting ways. We also encourage the writing of short articles to share the knowledge gained with other people in the web development community.

Stuck on 4096 characters???

26 Oct 2007

I’ve come up with a problem recently returning data via an XML feed using AJAX. In my case I was returning a list of images each having several links to perform various tasks (e.g. set as main image, add as thumbnail, add full image, etc).

The first load would go through fine and all images and their links would appear as I’d expect. There was also no problems in IE7, Safari (on Windows), or Opera 9+. When it came to Firefox 2 the image list would be cut short! Editing the javascript it basically seems that the returned data would be cut off at 4096 characters.

It took a while to track down the result. I thought initially this might of been a javascript maximum string length problem, but that other browsers just let the issue slip. Not that either. Anyway it turns out that text nodes are split at 4096 characters.

It’s quite simple to fix you simply need to normalise() your returned data in your AJAX script. Simply add the second line once you’ve gathered your XML data:

xmlResponse = xmlHttp.responseXML;
xmlResponse.normalize();

This will solve the 4096 character limit when using Firefox 2 or any other browser I haven’t checked that doesn’t normalise the data automatically.

Quick and easy $_POST security…

25 Oct 2007

A quick and easy way to protect yourself from mySQL injection attacks in PHP is to use…

$sql = "insert into table set ";
 foreach ($_POST as $key => $data)
 {
     $sql .= $key." = '".strip_tags(htmlentities(addslashes($data)))."',";
 }
 $sql .= mysql_query(rtrim($sql,',').";") or die(mysql_error());

What this script does is to take your $_POST data and remove anything malicious from it. Looping over the $_POST data we build up an SQL statement. At the end then we simply execute using with mysql_query.

NOTE: This does not validate your data, it just helps prevent malicious attacks.

Another version of this that I use to to grab all my form information into variables to to place the following code within the foreach loop instead…

eval("$".$key." = '".strip_tags(htmlentities(addslashes($data)))."';");

This makes up a list of variables following your forms field names and strips malicious code from them. This method then allows you to do some form validation before inserting data into your tables

Including an RSS Feed on your site…

26 Sep 2007

I’ve used my RSS feed generator on a few sites now, so I figure it’s about time I share. The final output validates and conforms to RSS2.0 standards so it will import into most things. I’ve even got mine linked to my facebook profile. The full code is at the bottom of the page.

Basically I use my RSS script to generate news feeds for the sites that I write. Examples can be seen on these sites,

But generally you can use the feed generator to serve any information you wish. For example would be the results of a search query where the query variables can be picked up from $_GET[]’s $_POST[]’s.

Anyway a question a friend asked me was “What’s the Point in RSS” good question! Click on the link to find out

Right anyway onto the script. Firstly we need to tell the browser or news-aggregator that it’s looking at a rss:xml feed,

  1. // Write the RSS header
  2. header("Content-Type: text/xml;charset=utf-8");

It’s at this point that I usually set up my database connection and link to the information I require so usually it’ll be something like,

  1. include_once( "./connect.php" );
  2. $sql = mysql_query("select * from news order by ‘datePosted’ desc LIMIT 50;" );

I limit to 50 as no one wants to see 1000’s of posts going back years and years unless they specifically ask for it Then we start writing out the ‘introduction’ part of the feed,

  1. echo "<!–l version=\"1.0\" encoding=\"utf-8\"–>";
  2. echo "<rss version="\"></rss>";
  3. echo "<channel></channel>";
  4. echo "";
  5. echo "<description>YOUR SITE/FEED DESCRIPTION</description>";
  6. echo "<link>".$_SERVER[‘HTTP_SERVER’]."</link>";

Then we loop through our items (in this case news articles) printing the data out to our xml file,

  1. // loop through the array pulling database fields for each item
  2. while ($newsItem = mysql_fetch_assoc($sql))
  3. {
  4.         $title                  = textFormat($newsItem[‘news_title’]);
  5.         $link                   = $_SERVER[‘HTTP_SERVER’]."news.php#news".$newsItem[‘id’];
  6.         $description    = textFormat($newsItem[‘news_item’]);
  7.         $uid                    = "tag:".$_SERVER[‘HTTP_SERVER’].",2007-09-26:rss.".$newsItem[‘id’];
  8.         $pubDate                = date("D, d M Y H:i:s O", strtotime($newsItem[‘date_posted’]));
  9.         echo "<item></item>";
  10.     echo "";
  11.     echo "<link>".$link."</link>";
  12.     echo "<description>".$description."</description>";
  13.     echo "
  14. <pubdate>".$pubDate."</pubdate>";
  15.     echo "<guid isPermaLink="\">".$uid."</guid>";
  16.     echo "";
  17. }

Remember for our RSS feed all text should be UTF-8 encoded so we include a little function to do this,

  1. function textFormat($intext) { return utf8_encode(htmlspecialchars(stripslashes($intext)));}

Then it’s just a simple case of closing down our xml tree and we’re all done,

  1. echo "";

Pretty painless wasn’t it And you can use these feeds to output anything of use. If someone is returning to your site to check for updated information should it be course dates, news items, forum posts, blog entries, even property searches it can all be done using RSS feeds.

Here’s the entire script:

  1. <!—->//==========================================
  2. // Author: Steven Lloyd Watkin
  3. // Company: Evilprofessor Designs
  4. // Website: http://www.ep-projects.co.uk
  5. // Date: June 2007
  6. // Feel free to use and modify, but please
  7. // include reference to my site somewhere
  8. //==========================================  
  9.  
  10. function textFormat($intext) { return utf8_encode(htmlspecialchars(stripslashes($intext)));}  
  11.  
  12. header("Content-Type: text/xml;charset=utf-8");
  13. echo "<!–l version=\"1.0\" encoding=\"utf-8\"–>";
  14. echo "<rss version="\"></rss>";
  15. echo "<channel></channel>";  
  16.  
  17. // retrieve database records
  18. include(‘connect.php’);
  19. $sql = mysql_query("select * from ‘news’ order by ‘datePosted’ desc");  
  20.  
  21. echo "";
  22. echo "<description>YOUR SITE/FEED DESCRIPTION</description>";
  23. echo "<link>".$_SERVER[‘HTTP_SERVER’]."</link>";
  24.  
  25. // loop through the array pulling database fields for each item
  26. while ($newsItem = mysql_fetch_assoc($sql))
  27. {
  28.         $title                  = textFormat($newsItem[‘news_title’]);
  29.         $link                   = $_SERVER[‘HTTP_SERVER’]."news.php#news".$newsItem[‘id’];
  30.         $description    = textFormat($newsItem[‘news_item’]);
  31.         $uid                    = "tag:".$_SERVER[‘HTTP_SERVER’].",2007-09-26:rss.".$newsItem[‘id’];
  32.         $pubDate                = date("D, d M Y H:i:s O", strtotime($newsItem[‘date_posted’]));
  33.         echo "<item></item>";
  34.     echo "";
  35.     echo "<link>".$link."</link>";
  36.     echo "<description>".$description."</description>";
  37.     echo "<pubdate>".$pubDate."</pubdate>";
  38.     echo "<guid isPermaLink="\">".$uid."</guid>";
  39.     echo "";
  40. }
  41. echo "";
  42. ?>

Latest News

Web Standards
Web Standards
Evilprofessor Designs makes a huge effort to make sure all websites conform to web standards set out by the W3C. This not only ensures that your web pages look consistently good in the vast majority of browsers, but that they are compatable with future standards of web design, and still display clearly on older internet browsers.

ImageBest technolgies
We make use of the best technologies to ensure that your site runs quickly and efficiently and displays the correct information for your customers. Evilprofessor Designs work primarily with PHP and mySQL but if you have a current site written in another language (e.g. ASP) we have experience in many other technologies. Currently we are training in AJAX and other so called Web 2.0 technologies. We are also familiar with several open source web solutions (such as Zen Cart, OSCommerce, Wordpress, etc) which means we can provide you with powerful websites with the minimum of cost and time.