Archive for the 'PHP' Category

Sending Emails in PHP Example

Tuesday, August 10th, 2010

With the help of smartwebby.com, we are able to show you the basic example when sending an email in PHP.

Syntax: mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]] )

Ex:

Sample PHP Code:

<?php

//Check whether the submission is made
if(isset($hidSubmit)){

//Declarate the necessary variables
$mail_to=$txtEmailto;
$mail_from=$txtEmailfrm;
$mail_sub=$txtSub;
$mail_mesg=$txtMsg;

//Check for success/failure of delivery
if(mail($mail_to,$mail_sub,$mail_mesg,”From:$mail_from/r/nReply-to:$mail_from”))
echo “<span class=’red’>E-mail has been sent successfully from $mail_sub to $mail_to</span>”;
else
echo “<span class=’red’>Failed to send the E-mail from $mail_sub to $mail_to</span>”;
}
?>

Sending Emails in PHP

Saturday, July 10th, 2010

During the 80’s, people still communicate through snail mails until electronic mails came in. Most professionals in today’s time spend 50% of their working time using e-mail and its use is no doubt increasing due to globalization.

Sending emails procedure varies. One of them is sending in PHP. Mails in PHP are easily  sent with the help of library function ‘mail‘.

This function takes four parameters to send E-mails from a PHP page and returns ‘true‘ upon successful delivery of Email. The parameters of this function are as follows:

  • Recipient
  • Subject
  • Message
  • Headers (Sender E-mail address)

Libraries and Extension

Saturday, April 10th, 2010

Libraries > PHP includes a large number of free and open source libraries with the core build.

Extensions > PHP allows developers to write extensions in C to add functionality to the PHP language. These can then be compiled into PHP or loaded dynamically at runtime. Extensions have been written to add support for the Windows API, process management on Unix-like operating systems, multibyte strings (Unicode), cURL, and several popular compression formats. Some more unusual features include integration with Internet relay chat, dynamic generation of images and Adobe Flash content, and even speech synthesis. The PHP Extension Community Library (PECL) project is a repository for extensions to the PHP language. -Source

Using Cookies in PHP

Wednesday, March 10th, 2010

What is a Cookie?Cookies are small bits of information that can be stored on a client computer. Once a cookie is created, it will expire after a specified time period. All the information stored in a cookie exist until it expires or deleted by the user.

Why do we need Cookies? Now-a-days most of the websites use cookies to store small amounts of information. Websites can read the values from the cookies and use the information as desired. The browser is capable of keeping track of the websites and their corresponding cookies and is capable of reading the information from relevant cookies. Some common use of cookies include:

  • User’s aesthetic preference for a specific site.
  • User keys to link them with their personal data – as used by many Shopping Cart Applications.
  • Allowing a user to remain ‘logged on’ until he explicitly logs out or the browser window is closed.

-Source

Creating Your Own “Function”

Wednesday, February 10th, 2010

A function is a block of code that can be executed whenever we need it.

Creating PHP functions:

* All functions start with the word “function()”
* Name the function – It should be possible to understand what the function does by its name. The name can start with a letter or underscore (not a number)
* Add a “{” – The function code starts after the opening curly brace
* Insert the function code
* Add a “}” – The function is finished by a closing curly brace

Example

A simple function that writes my name when it is called:

<html>
<body>

<?php
function writeMyName()
{
echo “Michelle”;
}

writeMyName();
?>

</body>
</html>

Use a PHP Function

Now we will use the function in a PHP script:

<html>
<body>

<?php
function writeMyName()
{
echo “Michelle”;
}

echo “Hello world!<br />”;
echo “My name is “;
writeMyName();
echo “.<br />That’s right, “;
writeMyName();
echo ” is my name.”;
?>

</body>
</html>

The output of the code above will be:

Hello world!
My name is Michelle.
That’s right, Michelle is my name.

PHP + MySQL

Sunday, January 10th, 2010

PHP stands for PHP: Hypertext Preprocessor. It is a server-side scripting language wherein the scripts are executed on the server itself. PHP is an open source software and is free to download and use. MySQL is a database server that is ideal for both small and large applications. MySQL can compile on a number of platforms and just like PHP, it is free to download and use. Both are open to everybody who wants to learn more on this.

PHP combined with MySQL can create a cross-platform which means that you can freely develop in Windows and serve on a Unix platform.

User Validation

Wednesday, December 9th, 2009

The golden rule on the world wide web is that one should “never-ever-ever trust user input”. Given this, it would be wise to spend quite some time to make sure that all of the inputs from the users in able to make sure it is safe and what was expected..

There are several things to should watch out for when validating input:

Mistaken input.
For example the user types 99.7 rather than 9.97
Bad input
The user provides incorrect input in on purpose for whatever reason.
Dangerous input
User innocently enters information that would harm the system
Missing input
User provides no input.

ASP vs PHP: Security

Friday, October 30th, 2009

In PHP, common tasks like ftp, encrypt passwords in MD5, or send email from a web page all are built in hidden code, and as PHP is Open source there is a lot
of free code available for PHP.

Unlike PHP there is no hidden code with ASP. If you need to upload files, then you would need a third party component like ASP upload, also if you need to send mail you need another component and so on.

Although PHP is better in many aspects, ASP offers more security than PHP.

ASP vs PHP: Price and Versatility

Monday, September 28th, 2009

Price Compared to ASP, PHP installations are absolutely cheaper to install. PHP perfectly runs on Linux (which is a free OS) and programmers use MySQL .(which also comes FREE) ASP runs on the IIS Server (Internet Information Server) which requires Windows N.T/2000/2003 Servers or better. Aside from that ASP mostly uses MS-SQL Server as the back end which is really expensive. PHP obviously is cheaper than ASP.

Cross Platform compatibility
PHP programs run on a wide variety of Operating Systems Unix, Linux, Solaris and Window’s.ASP on the other hand only works flawlessly with Windows and not with other platforms. PHP offers more versatility than ASP.

Smarty – the right stuff?

Monday, June 22nd, 2009

Smarty is categorized as a “Template engine”, though developers describe it more detailed as a “Template/Presentation Framework”, that offers developers and programmers ample tools to make extensive coding tasks easier by replacing tags with their appropriate counterparts. Smarty is aimed to hasten and make the development process simpler for all who aim to develop pages for the internet. (more…)