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>