Archive for the 'Basic Programming' Category

What is the Best PHP Program for Use?

Tuesday, November 10th, 2009

Best Php Software

PHP can be done through a lot of programming languages. This can be from the simple notepad authoring (a practice that can be done by advanced programmers who are already familiar with PHP programming) or from PHP ready programs such as Dreamweaver.

It would be best however to read on more on which software can be suitable for you. PHP is a common scripting technique these days and some even download basic scripts and enhance them afterwards. This approach is actually a learning process and in the end, you will find yourself starting from scratch and making your own scripts for self-improvement in the world of website design and development.

Steps in Creating a Simple User Log

Sunday, July 19th, 2009

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 ().

Don’t be an elitist!

Tuesday, February 10th, 2009

One of the most basic mistakes people make in PHP programming is failing to resize their images and files. Because it is supposedly a “small” thing, this is precisely what makes it easy for many PHP programmers to overlook.

Dont be an elitist!

Don't be an elitist!

What the failure to resize simply does is to make your site harder to access, as people with slower internet connections or short attention spans (or worse, both) will just skip viewing your site altogether, which would be a shame if your site and your content is well crafted. You might as well put a big bright disclaimer on your site that says, “People with slow internet connections – GO AWAY.” And that, friends, is elitism, albeit unintentionally done.

Looping Statement At PHP

Sunday, 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

.htaccess Password Protection

Friday, 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)

Monday, 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)

Friday, 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.