Archive for the 'PHP' Category

PHP Image Uploader Program Code

Friday, December 10th, 2010

This PHP Program is useful when you want to upload images only.

$numoffiles = 5;
echo '

‘ ;
for ($i = 1; $i<=$numoffiles; $i++)
{
echo 'Image'.$i.':
‘;
}
echo ‘
‘;
echo ‘

‘;

if(isset($_POST['action']))
{
$uploaddir = ‘C:/PHP/uploadtemp/’;
for ($i =0; $i<$numoffiles; $i++)
{
$filename = $_FILES['file']['name'][$i];
$filetmp = $_FILES['file']['tmp_name'][$i];
$filesize = $_FILES['file']['size'][$i];
$filetype = $_FILES['file']['type'][$i];
$ext = substr(strrchr($filename, "."),1);
$conf = $uploaddir . $filename;
$filepath = $uploaddir . $filename;

if ($filename != "")
{

if (!file_exists($filepath))
{
if ($ext == "jpg" || $ext == "gif" || $ext == "tiff" || $ext == "png" || $ext == "bmp")
{
if($filesize < "500000")
{
$upload = move_uploaded_file($filetmp, $filepath);
echo '‘. $filename . ‘ was successfully uploaded…
‘;
}
else
{
echo ‘‘.$filename . ‘ greater than the maximum file size allowed…
‘;
}
}
else
{
echo ‘‘. $filename . ‘ is invalid file type…
‘;
}
}
else
{
echo $filename . ‘ already exists…
‘;
}
}

}
}

?>

Single Quotes and Double Quotes Rage On

Wednesday, November 10th, 2010

Don’t you know whenever you place ‘double quotes you are asking for PHP to look after the content of a variable? PHP will still waste valuable computing time scanning lines even if the following lines do not contain variables inside the double quotes.

Such three lines of codes can be done even speedy if “single” quotes were used in place of “double” ones.

In the present, that may not seem like much, but making PHP check for variables where it doesn’t need to over the course of a larger script, can certainly impede run-time. Just to clarify my point, PHP will not read a variable if it is within ‘single’ quotes.

To keep your scripts fast in your server, avoid double quotes at all costs. Even if you’re working with variables yet you’re thinking of using double scripts.

The Most Recommended Web Programming Today

Sunday, October 10th, 2010

One of the simplest tools for web applications is the ASP.Net with C# or VB.Net. The C# is the future language for the web which speeds up the development cycle, and other suggested languages for the web. Also, JavaScript syntax would not be too difficult to pickup C#. Likewise, if it is with VBScript, then VB.Net. won’t be difficult to learn.  However, it is a known fact that higher demand goes to the C# developers than those in the VB.NET. The longetivity, validation of technology, the development cycle time and the compatibility concerns should be considered in choosing a platform.

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.