Tips for Php

November 25th, 2008

Image Source: filemaker.com

If you are new to programming, chances are you will be more likely intimidated by PHP. PHP is the newest scripting language that is gaining popularity across the globe. This is simply because it provides a very basic principle in programming. No complicated stuff that will get you lost along the way. In relation to this, your fear of PHP is due to the fact you might have a limited understanding on how it works. Because once you get to know the important details, you should have no problem programming your stuff in no time. The most important thing you should know before you come to like PHP is an extensive understanding of HTML. This is primarily because PHP and HTML wil supplement each other in your programming.

Cookies: Monsters?

October 6th, 2008

Image Source:images.malwarehelp.org

HTTP or Hyper Text Transfer Protocol is basically stateless. It simply means that any data that you have made starts from scratch again when the page that you requested has been sent and the connection between them is terminated. Developers worked on, to find a way to solve the problem. The first to come up with the idea of storing small data on the client was Netscape. They eventually created the “cookies” as the solution to that problem. The Netscape browser came up with cookies. These are small bits of information that a particular website on the client’s computer. These will then be sent back by the PC to the website every time that particular page was requested. a cookie can olny be used by the website that wrote them. It is a secure way to store data between pages. Cookies made some negative headlines a few years back. Initially it was thought that these cookies were employed and installed in the PCs to stalk users’ confidential infos. And came to a point that it was encouraged to disable cookies when browsing. But in the end, people got the real deal about the cookies and why its there. They’re basically harmless.

Getting Your Php Certification

September 29th, 2008


Image Source:static.zend.com

Want to become a PHP programmer? PHP Certification is a type of exam in which you are required to pass a single test containing about 70 multiple choice questions. It was developed by the creator of PHP himself. If you pass this exam, you will be qualified to the next level which they call
Zend Certificate Engineer or ZCE. Currently, the medium for learning is PHP5. Gather study materials that are already based on PHP5.

What is all this for? You might ask. Basically, its sort of an online degree or certificate. The most important concept of this program is professional recognition. You can then use this to pursue your PHP programming career.

Looping Statement At PHP

August 10th, 2008


Image Source: www.ariel.web.id
Looping statements, like Do-While looping statements, While looping statements, and For looping statements, makes programming very easy, even at making PHPs. But did you know that there is something that looping statements can’t loop? That’s right! There is something. Looping statements can’t loop If-Else statements. That’s because when the looping statement starts, it goes through the If-Else statement, and then, whatever the statement the If-Else statement supplies, it will be the new statement the looping statement loops, and the If-Else statement will be left aside. I’ve been creating PHPs in our school and I tell you, it’s very frustrating that your looping statements are not looping the whole statements you put inside it. Thus, your website will not work properly. The only solution that I find is that you have to use Switch statements. Switch statements are like If-Else statements, but the Switch statements are more specific. Try it! It works, even at other programming language

Good Features of the evolt PHP Login system

July 15th, 2008

Photobucket

As an example of secure PHP programming, the evolt PHP login system has a list of good features as follows:

Safety – Passwords are not saved in cookies

Levels – Users are identified by different levels (admin, user etc.)

Admin Center – As admin, you have full management of the users. View user profiles, delete and ban users, demote and upgrade user levels.

Tracking – You can now tell how many visitors and registered users are viewing your site. Also it will show how many users your site has.

Account Info – Registered users can edit and view their own information and also view other’s profile as well.

Error Form – If an error occurs, they are redirected to an error form page that they can fill out to inform that there is an error page and error that occurred are displayed.

Password – If users forget their password, they can have a new one generated and sent to their email.

Introduction to Functions in PHP

June 4th, 2008

First of all what is a Function? A Function is a small set of statements defined by the programmer to do a specific action. They take input values in the form of ‘arguments‘ and return values after execution. They can be written anywhere in the program. They are used to reduce the programming complexity and to handle the programming structures easily. The function takes an input, performs some operation with it and returns a value after successful execution. Functions are basically of two types, namely:

  • Functions with no return value
  • Functions with return values

-Source

.htaccess Password Protection

May 30th, 2008

securelock.jpg

Even without using mySQl, users can still password protect their files through .htaccess password protection.

The code can be divided into 3 if-else statements:

1. If the user has not been validated, use the PHP header and request for a username and password.

2. Else, if the user’s name is “webworld” and the password is “webworld”, log in. Here, all the code for the user will be placed.

3. Else say the user/password failed.

//1st part
if (!isset($PHP_AUTH_USER))
{
header("WWW-Authenticate: Basic realm=\"webworld Password.\"");
Header("HTTP/1.0 401 Unauthorized");
exit;
}

//2nd part
else if(($PHP_AUTH_USER=="webworld") && ($PHP_AUTH_PW=="webworld"))
{
echo "You are logged in...";
//put the code for the whole user page in here
//you can also create a redirect to the user page if you want
}

//3rd part
else
{
echo "Failed entry”;
//fail try again
}
?>

Remember that the username and password will remain for the whole session as long as explorer windows is open.

Displaying Page Loading Time (Steps and Sample Code)

May 26th, 2008

stopwatch.gif

Here is how to display your page’s loading time:

1. Use the function microtime() to get the time in micro-seconds
2. Use the explode() function to turn the micro-time into an array.
3. Combine the two parts to the array (the micro-seconds to the seconds).
4. Repeat steps 1,2 and 3 for the bottom of the page
5. Take the time taken at the end of the page from the time taken at the top of the page to determine the total loading time.
6. After rounding the microtime, return it to the browser.

At the top of your page, place:

$m_time = explode(" ",microtime());
$m_time = $m_time[0] + $m_time[1];
$starttime = $m_time;
?>

At the bottom of your page, place:

$round = 3;// The number of decimal places to round the micro time to.
$m_time = explode(" ",microtime());
$m_time = $m_time[0] + $m_time[1];
$endtime = $m_time;
$totaltime = ($endtime - $starttime);
echo "Page loading took:". round($totaltime,$round) ." seconds";
?>

Creating a Simple User Log (Sample Code)

May 23rd, 2008

wwwglobe.jpg

//use the date() function <----- comment
$time = date("F jS Y, h:iA");

//use PHP variable $remote_addr to get ip address
$ip = $REMOTE_ADDR;

//use PHP variable $http_referer to get referer
$referer = $HTTP_REFERER;

//user PHP variable $http_user_agent to get browser
$browser = $HTTP_USER_AGENT;

//what page they came from
$page = $_SERVER['REQUEST_URI'];

//use the fopen() function
$fp = fopen("log.html", "a");

//use the fputs() function
fputs($fp, "
Time: $time
IP: $ip
Referer: $referer
Browser: $browser
Page: $page
");

fclose($fp);

?>

Note: Don’t forget to create a blank log.html page, upload it to the server in the same directory as the page where the code will be placed, and CHMOD it to 777. Also, you can put this code anywhere on your main page.

Steps in Creating a Simple User Log

May 19th, 2008

user_logtime1.gif

If you want to keep track of who has been visiting your web site and their destination, it would be a good idea for you to create a simple user log. The user log that will be used here will be stored in on a flat file and will store four basic functions: a) Time when the user accessed your page; b) User’s IP address; c) If available, the user’s referrer, and; d) User’s browser. Make a log.html and CHMOD it to 777, giving all permissions to the file. Use the date () function to set time. The four basic functions are built into PHP (all you need to do is to define the functions and send them to a log HTML file) so all other variables are already predefined. Using fopen (), the second part of the script will open up log.html and write the data in using fputs ().


Bad Behavior has blocked 70 access attempts in the last 7 days.