Php

HTTP Authentications using PHP

Fadıl

The HTTP Authentication hooks in PHP are only available when it is running as an Apache module and is hence not available in the CGI version. In an Apache module PHP script, it is possible to use the Header() function to send an “Authentication Required” message to the client browser causing it to pop up a Username/Password input window. Once the user has filled in a username and a password, the URL containing the PHP script will be called again with the variables, $PHP_AUTH_USER, $PHP_AUTH_PW and $PHP_AUTH_TYPE set to the user name, password and authentication type respectively.

Email Validation In PHP

Fadıl

Ever have those annoying spammers sign up for something with their email addy and always make up some donkey crap? Well, here is a script that will allow you to block some of that.

We are going to create this script as a function.

//->Email validation script

function validate_email($email) { 
if (eregi("([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+)", $email)) return 1; 
else return 0; 
} 
?>

Now time for an example with the function included.

$email = "[email protected]" 
if (validate_email($email)) print "E-mail Address Approved"; 
else print "Nice Try Spammer";

If there are any problems with the script just let me know.

How To Set A Cookie

Fadıl

Cookies are little pieces of text that are sent to a user’s Web browser. Cookies can help you create shopping carts, user communities, and personalized sites. It’s not recommended that you store sensitive data in a cookie, but you can store a unique id string that will match a user with the data held securely in a database.

Enough with the boring stuff here is how to set a cookie using the setcookie() command.

How to Finding Out Your Server Specs Through A PHP Script

How to Finding Out Your Server Specs Through A PHP Script

Fadıl

Have you ever need to know what your server is running?  Need to see if it runs MySQL?  Well here is a way of knowing what options are available in PHP and what’s going on in your server is to use the phpinfo() function. Create a script with the following.

<html> 
<body> 
<?php 
phpinfo(); 
?> 
</body> 
</html>

Save and view this script through your Web server. You’ll see a page filled with useful and interesting information.  This info tells all about your server, internal Web server environment variables, the options that are compiled, and on and on.
I hope it has been a useful article.

How to Creating A Page Counter In PHP

Fadıl

OK,  everybody has a hit counter on their page.  But how many people actually make their own?  Ya well, I am going to show you how to create a simple page counter in PHP.

This page counter writes to a file that you have created, storing how many hits you have received.  The script then reads the text file (counter.txt) and displays it on the page.  Let’s take a look at this code in action.