Total Pageviews

Friday, November 26, 2010

PHP Simple mail function

 <?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

Sunday, November 14, 2010

Form Validation

<script language="javascript" type="text/javascript">
function verify()
{
if (document.forms[0].elements[0].value=="")
{
  alert("Please Enter your Name");
  document.forms[0].elements[0].focus()
  return(false);
}

if (document.forms[0].elements[2].value=="")
{
  alert("Please Enter your City");
  document.forms[0].elements[2].focus()
  return(false);
}
if (document.forms[0].elements[4].value=="")
{
  alert("Please Enter your Country");
  document.forms[0].elements[4].focus()
  return(false);
}

if(document.forms[0].elements[5].value.indexOf(" ") >= 0)
{
 alert("Please enter your email-id without any white space character.");
  document.forms[0].elements[5].value="";
  document.forms[0].elements[5].select();
  document.forms[0].elements[5].focus();
 return (false);
}
if ( (document.forms[0].elements[5].value.indexOf("@") == -1) || (document.forms[0].elements[5].value.indexOf(".") == -1) )
{
 alert("Please enter a valid email-id");
  document.forms[0].elements[5].value="";
  document.forms[0].elements[5].select();
  document.forms[0].elements[5].focus();
 return (false);
}
BeforeAtRate = document.forms[0].elements[5].value.substring(0,document.forms[0].elements[5].value.indexOf("@"));
AfterAtRate = document.forms[0].elements[5].value.substring(document.forms[0].elements[5].value.indexOf("@")+1,document.forms[0].elements[5].value.length);
if (AfterAtRate.indexOf(".") == -1)
{
 alert("Please enter a valid email-id");
  document.forms[0].elements[5].value="";
  document.forms[0].elements[5].select();
  document.forms[0].elements[5].focus();
 return (false);
}
middle = AfterAtRate.substring(0, AfterAtRate.indexOf("."))
last = AfterAtRate.substring(AfterAtRate.indexOf(".") + 1,AfterAtRate.length)
if (BeforeAtRate.length == 0 || middle.length == 0 || last.length == 0)
{
 alert("Please enter a valid email-id");
  document.forms[0].elements[5].value="";
  document.forms[0].elements[5].select();
  document.forms[0].elements[5].focus();
 return (false);
}
if (document.forms[0].elements[6].value=="")
{
  alert("Please Enter your Phone Number");
  document.forms[0].elements[6].focus()
  return(false);
}
if(isNaN(document.forms[0].elements[6].value))
   {
     alert("Invalid data format.\n\nOnly numbers are allowed.");
     document.forms[0].elements[6].value="";
  document.forms[0].elements[6].select();
  document.forms[0].elements[6].focus();
     return (false);
   }
if (document.forms[0].elements[7].value=="")
{
  alert("Please Enter your Message");
  document.forms[0].elements[7].focus()
  return(false);
}
}
</script>

Friday, November 12, 2010

Sending and Receiving Cookies in PHP Scripts

  • setcookie() must be called before any output to the HTTP response. The main reason is that PHP is not buffering the HTTP response. But you can alter this behavior by using the ob_start() functions.
  • A persistent cookie is stored in a cookie file on the browser's local machine.
  • A persistent cookie can have an expiration time expressed in number of seconds since epoch.
  • Web browser will only send back a cookie when both domain and path match the requested domain and path.
  • To make a cookie available for all sub domains of a top level domain, set the domain property to the top level domain name.

Thursday, November 11, 2010

T-Mail

Bell Atlantic have introduced a new service called T-Mail that allows groups and organisations to communicate via their telephone. The trial began in Montgomery County, USA where every single person has been given their own T-Mail mailbox. Bell Atlantic have been working with a variety of selected organisations and groups through the summer putting in applications where the group could send a single message through their telephone to hundreds of group members with a single phone call. Each member has been given their own free mailbox to receive messages.
According to Bell Atlantic the response has been very good and has created an interest amongst other organisations, schools, and groups. Some of the initial successful applications have included day care centres, sports teams, as well as other formal and informal groups. It will not be used by telemarketing companies, but for organisations and groups that are relying upon "telephone trees," monthly newsletters, and word of mouth to communicate information. Although the system does not appear to have been specifically used for education and training, it could be an interesting alternative to electronic mail and an extension to the voice mail systems which are now starting to be used across Europe.

XML in PHP 5

Almost everything regarding XML support was rewritten for PHP 5. All the XML extensions are now based on the excellent libxml2 library by the GNOME project. This allows for interoperability between the different extensions, so that the core developers only need to work with one underlying library. For example, the quite complex and now largely improved memory management had to be implemented only once for all XML-related extensions.
In addition to the better-known SAX support inherited from PHP 4, PHP 5 supports DOM according to the W3C standard and XSLT with the very fast libxslt engine. It also incorporates the new PHP-specific SimpleXML extension and a much improved, standards-compliant SOAP extension. Given the increasing importance of XML, the PHP developers decided to enable more XML support by default. This means that you now get SAX, DOM and SimpleXML enabled out of the box, which ensures that they will be installed on many more servers in the future. XSLT and SOAP support, however, still need to be explicitly configured into a PHP build.

Create google custom search for your website

<!-- Use of this code assumes agreement with the Google Custom Search Terms of Service. -->
<!-- The terms of service are available at http://www.google.com/cse/docs/tos.html -->
<form name="cse" id="searchbox_demo" action="http://www.google.com/cse">
  <input type="hidden" name="cref" value="" />
  <input type="hidden" name="ie" value="utf-8" />
  <input type="hidden" name="hl" value="" />
  <input name="q" type="text" size="40" />
  <input type="submit" name="sa" value="Search" />
</form>
<script type="text/javascript" src="http://www.google.com/cse/tools/onthefly?form=searchbox_demo&lang="></script>
                               

Creating a Code Search Engine with PHP and MySQL

The Database Schema

Just a single table is required for the engine's operation. The table, code, serves as the code repository. Each example is stored along with a suitable title and the chapter number in which it appears. Because the search engine should retrieve examples based on keywords found in the example title or in the code itself, a FULLTEXT index has been added for these columns. Because the table contents will rarely change beyond the occasional bug fix, its backed by the read-optimized MyISAM storage engine. The table follows:
CREATE TABLE code (
 id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
 title VARCHAR(50) NOT NULL,
 chapter TINYINT UNSIGNED NOT NULL,
 code TEXT NOT NULL,
 FULLTEXT (title,code)
) TYPE = MYISAM;

Loading the Table


The downloadable zip file containing all of the book's code should be easily navigable so readers can easily retrieve the desired example. To meet this requirement, the zip file contains a number of directories labeled according to chapter number (1, 2, 3, ... 37), and each script is aptly named with a lowercase title and series of underscores, for example retrieving_array_keys.php. Therefore a script capable of dealing with these two organizational matters is required in order to automate the process of loading the scripts into the database.
You might recognize this task as one well suited for recursion, and indeed it is. The following script does the job nicely:
<?php

mysql_connect("localhost","gilmore","secret");

mysql_select_db("beginningphpandmysqlcom");

// Running on Windows or Linux/Unix?
$delimiter = strstr(PHP_OS, "WIN") ? "\" : "/";

function parseCodeTree($path) {

  global $delimiter;

  if ($dir = opendir($path)) {
 
    while ($item = readdir($dir)) {

      // If $item is a directory, recurse
      if (is_dir($path.$delimiter.$item) && $item != "." && $item != "..") {
   
        //printf("Directory: %s <br />", $item);
        parseCodeTree($path.$delimiter.$item);

      // $item is a file, so insert it into database
      } elseif ($item != "." && $item != "..") {

        // Retrieve the chapter number
        $directory = substr(strrchr($path, "$delimiter"), 1);

        //printf("File: %s <br />", $item);

        // Convert the file name to a readable title
        $scriptTitle = str_replace(".php", "", $item);
        $scriptTitle = str_replace("_", " ", $scriptTitle);
  
        // Retrieve the file contents
        $scriptContents = file_get_contents($path.$delimiter.$item);

        // Insert the file information into database
        $query = "INSERT INTO code VALUES
('NULL', '$scriptTitle', '$directory', '$scriptContents')"; $result = mysql_query($query); } } closedir($dir); } return 1;}parseCodeTree('code');?>
I've purposefully left two printf() statements in the script so you can view the script's logic. Some sample output follows:

Directory: 4
File: array_key.php
File: is_array.php
Directory: 5
File: multidimensional_array.php
File: retrieving_array_keys.php
File: retrieving_array_values.php
File: slicing_an_array.php

Building the Search Engine

With the code and corresponding metadata inserted into the database, all that's left to do is build the search engine. Believe it or not, this is perhaps the easiest part of the project, thanks to MySQL's fulltext search capabilities. Although I've used the symfony framework to abstract the database interaction, for the purposes of this article I've used POPM (Plain Old PHP and MySQL) to build the search engine. The search form is exceedingly simple, and looks like this:
<form method="POST" action="search.php">
Search the code repository:<br />
<input type="text" id="keyword" name="keyword" /><br />
<input type="submit" value="Search!" />
</form>
The search script (search.php) looks something like this. Provided you've used PHP to interact with MySQL before, there shouldn't be any surprises, except for perhaps the query itself. This query takes advantage of MySQL's fulltext feature to compare the keyword against those columns that have been identified as searchable using MySQL's fulltext conditions. These conditions can produce unexpected results without doing some advance reading, so be sure to peruse the appropriate section of the MySQL documentation before building your own queries.
<?php

  mysql_connect("localhost","gilmore","secret");
  mysql_select_db("beginningphpandmysqlcom");

  $keyword = mysql_real_escape_string($_POST['keyword']);

  // Perform the fulltext search
  $query = "SELECT id, title, chapter, code 
            FROM code WHERE MATCH(title, code) AGAINST ('$keyword')";

  $result = mysql_query($query);

  // If results were found, output them
  if (mysql_num_rows($result) > 0) {

    printf("Results: <br />");

    while ($row = mysql_fetch_array($result)) {

      printf("Chapter %s: <a href='displaycode.php?id=%s'>%s</a>", 
       $row['chapter'], $row['id'], ucfirst($row['title']));

    }

  } else {
    printf("No results found");
  }

?>

New PHP for Eclipse

This version is a major upgrade of this open source development tool. The emphasis in this release, said Roy Ganor, PDT project lead and team leader in Zend Technologies' developer group, is on providing PHP coders with a more professional development environment.
"Generally speaking, PHP developers have low standards when it comes to tooling -- especially in their ability to work with development teams," Ganor said. "Two or three years ago, most of the PHP developers worked with very basic tools, such as simple editors. But we -- Zend and IBM, which started the PDT three years ago -- predicted that they would soon demand a full-featured development environment. This release fulfills this demand."

Wednesday, November 10, 2010

PHP Content Editor

Pls follow this site to get full contents for PHP Content Editor

http://ckeditor.com/

PHP Basics

What You Should Already Know

Before you continue you should have a basic understanding of the following:
  • HTML/XHTML
  • JavaScript
If you want to study these subjects first, find the tutorials on our

What is PHP?

  • PHP stands for PHP: Hypertext Preprocessor
  • PHP is a server-side scripting language, like ASP
  • PHP scripts are executed on the server
  • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)
  • PHP is an open source software
  • PHP is free to download and use

What is a PHP File?

  • PHP files can contain text, HTML tags and scripts
  • PHP files are returned to the browser as plain HTML 
  • PHP files have a file extension of ".php", ".php3", or ".phtml"

What is MySQL?

  • MySQL is a database server
  • MySQL is ideal for both small and large applications
  • MySQL supports standard SQL
  • MySQL compiles on a number of platforms
  • MySQL is free to download and use

PHP + MySQL

  • PHP combined with MySQL are cross-platform (you can develop in Windows and serve on a Unix platform)

Why PHP?

  • PHP runs on different platforms (Windows, Linux, Unix, etc.)
  • PHP is compatible with almost all servers used today (Apache, IIS, etc.)
  • PHP is FREE to download from the official PHP resource: http://www.php.net/
  • PHP is easy to learn and runs efficiently on the server side

Where to Start?

To get access to a web server with PHP support, you can:
  • Install Apache (or IIS) on your own server, install PHP, and MySQL
  • Or find a web hosting plan with PHP and MySQL support

TinyMCE - Javascript WYSIWYG Editor

 

TinyMCE is a platform independent web based Javascript HTML WYSIWYG editor control released as Open Source under LGPL by  Moxieecode Systems  It has the ability to convert HTML TEXTAREA fields or other HTML elements to editor instances. TinyMCE is very easy to integrate into other Content Management Systems.

TinyMCE Features

  • Easy to integrate - Only a few lines of code needed.
  • Customizable - Themes and plugins, block invalid elements and force attributes.
  • Browserfriendly - Mozilla, MSIE, FireFox, Opera, Safari and Chrome.
  • Lightweight - PHP/.NET/JSP/Coldfusion GZip compressor, Makes TinyMCE 75% smaller and a lot faster to load.
  • AJAX Compatible - You can easily use AJAX to save and load content!
  • International - Multilanguage support using language packs.
  • Open Source - Free under the LGPL license, millions of ppl help test and improve this editor every day.

Sunday, November 7, 2010

 Create an Upload-File Form
 
<html>
<body>

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

Create The Upload Script

 <?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  }
?> 

 

Restrictions on Upload

 <?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Error: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Stored in: " . $_FILES["file"]["tmp_name"];
    }
  }
else
  {
  echo "Invalid file";
  }
?> 

 

Saving the Uploaded File

 <?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

Thursday, November 4, 2010

Video Thumbnail creation using PHP

Refer this usefull Link

http://www.iepak.com/30/TopicDetail.aspx

5 PHP Frameworks you may not know about

Segull

Seagull 5 PHP Frameworks you may not know about
Supports:

* PHP4
* PHP5
* Multiple Database’s
* ORM
* DB Objects
* Templates
* Caching
* Validation
* Ajax
* Auth Module
* Modules

PHP on TRAX

phpontrax 5 PHP Frameworks you may not know about
Supports:

* PHP5
* Multiple Database’s
* ORM
* DB Objects
* Validation
* Ajax
* Modules

Yii

Yii 5 PHP Frameworks you may not know about
Supports:

* PHP5
* Multiple Database’s
* ORM
* DB Objects
* Templates
* Caching
* Validation
* Ajax
* Auth Module
* Modules

Akelos

Akelos 5 PHP Frameworks you may not know about
Supports:

* PHP4
* PHP5
* Multiple Database’s
* ORM
* DB Objects
* Templates
* Caching
* Validation
* Ajax
* Auth Module
* Modules

Prado

PRADO 5 PHP Frameworks you may not know about
Supports:

* PHP5
* Multiple Database’s
* ORM
* DB Objects
* Templates
* Caching
* Validation
* Ajax
* Auth Module
* Modules