• Archives

  • Archive for the ‘PHP’ Category

    Php error handling

    Tuesday, May 27th, 2008

    Sometimes we need to set our own errors rather than the default one like this.

    Warning: fopen(test.txt) [function.fopen]: failed to open stream: No such file or directory in http://localhost/index.php on line 2

    it is good when you create scripts and sell

    Creating a basic error handler using the die function !!

    die(“File does not exist”);

    Set error handler

    Error handlers are set using




    function myerror($var1, $var2)
    echo “<b>Error:</b> [$var1] $var2”;



    Error will be

    Error: [8] Undefined variable: var



    opening and extracting a zip file

    Thursday, May 1st, 2008

    Well zipping is not a php function. For the zipping functions to work on your server you must download the

    Download the ZZIPlib library

    Download the Zip PELC extension

    And install them ( find the instruction there only on how to )

    The example i am going to tell is a simple one

    $zipfile = new ZipArchive;
    “the requested file has been extracted”;

    open = open the specified zip file inside the braces

    extractTo = extract the opened zip file to the location specified

    close = closes a zip file



    Free Search Engine For Your Site

    Sunday, February 17th, 2008

    TSEP is a simple, yet very powerful and fast PHP website search engine. It is built to index your site so it can be searched later within seconds. Some features: your own stopwords, logging, MySQL Boolean search, many languages, CSS formating.


    • TSEP is a search engine for a website – for your website!
      You can put a “Search this site” anywhere on your website and let people quickly find what they are looking for.
    • TSEP is free of charge and open source software.
    • TSEP is designed to be very easy to install and use.
    • TSEP can be implemented into your layout (there is also a pre-made search page available)
      With only two lines of code you can add TSEP to your website and into your layout!
    • TSEP uses CSS for formatting.
      You can adjust any color, font, anything of the look to your needs.
    • TSEP uses indexing profiles.
      The profiles enable you to split the indexing (and in future also the searching) process.
    • TSEP is localized!
      This means if you are running a website in the English language you will probably want to show the search page as well in English – you can do this with TSEP very easily. If you are running a website in German you can see the TSEP messages in German. French, Spanish, Italian, Thai, Chinese, Russian… . None of those should be a problem for TSEP.
    • TSEP supports (MySQL-) Boolean search terms.

    Website – http://tsep.info/cms/


    Echoing the user input through php

    Friday, February 1st, 2008

    Php is very powerful when it comes to handling of forms. It can check user input check for illegal characters and can also help in uploading of files. Which i am going to teach you in later chapters. But for today we are going to study how to how to echo user input.


    Displaying random advertisement through php

    Tuesday, January 1st, 2008


    Sometimes you want to display something randomlythis tutorial is going to teach how to display two company advertisement on the same page like google and bidvertiser.


    <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
    <html xmlns=”http://www.w3.org/1999/xhtml”>
    <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
    <title>Untitled Document</title>
    $a = rand (1,2);
    if ($a == “1″) {
    <script type=”text/javascript”>
    google_ad_client = “”;
    //728×90, created 12/31/07
    google_ad_slot = “1167745697″;
    google_ad_width = 728;
    google_ad_height = 90;
    <script type=”text/javascript”
    if ($a == “2″) {
    <!– Begin BidVertiser code –>
    <SCRIPT LANGUAGE=”JavaScript1.1″ src=”http://bdv.bidvertiser.com/BidVertiser.dbm?pid=&bid=” type=”text/javascript”></SCRIPT>
    <noscript><a href=”http://www.bidvertiser.com/bdv/BidVertiser/bdv_advertiser.dbm”>pay per click</a></noscript>
    <!– End BidVertiser code –>



    You must have understand now that we assign a randomly between 1 and 2 and then check if a = 1 then display google advertisement and if a = 2 then display bidvertiser advertisement.