Programming

Introduction to Java : Data Types and Operators Part-2

Fadıl

Data Types

Java is a “strongly typed language”. That means that type of every variable must be declared.

Consider the following simple variable assignments:

     boolean isASwingDancer = true;
     int age = 30;

In other words, Java requires that if a variable is meant to hold a boolean, it is declared as such. The same goes for ints and every other data type.

Once you declare a variable, it can never be changed to hold another type of value.

Introduction to Java : Data Types and Operators Part-1

Fadıl

Comments

It is often the case that you want to include comments within your Java code. Comments are little bits of documentation embedded in the actual code that is invisible to the Java compiler but which can be read by a person reviewing your code.

Comments help to document what it is that your code does and how someone should understand the design if they want to modify something. Comments are essential if someone else is going to work with you or take from where you’ve left off.

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.