You may have tried using $_SERVER['HTTP_USER_AGENT'] couple of times to get the name of your website visitor's browser. Unfortunately all browsers identify themselves with a long string that all started with Mozilla, for instance when you use the above PHP function Google Chrome will return this Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36.
However, in that string, all browsers contain a distinct name. So you can use that name to identify the users browser. You can use the stripos() PHP function to find the name in the string that is returned by the browser. The code below did that for you, you can just copy and paste it to see how it works, but i recommend you understand the logic, by using echo $_SERVER['HTTP_USER_AGENT']; in many browsers to see how each browser display the string.
<!DOCTYPE html>
<head>
<title>Testing</title>
</head>
<body>
$browser = $_SERVER['HTTP_USER_AGENT'];
if (stripos($browser, 'opr') == true)
{
echo "Your Browser is Opera.";
}
else if (stripos($browser,'chrome') == true)
{
echo "Your Browser is Google Chrome.";
}
else if (stripos($browser,'trident') == true)
{
echo "Your Browser is Internet Explorer.";
}
else if (stripos($browser,'flock') == true)
{
echo "Your Browser is flock.";
}
else if (stripos($browser,'firefox') == true)
{
echo "Your Browser is Mozilla Firefox.";
}
else if (stripos($browser,'safari') == true)
{
echo "Your Browser is Safari.";
}
?>
</body>
</html>
Wednesday, 7 May 2014
Monday, 21 April 2014
JAVA OOP DEMONSTRATION
I'm gonna show you how Java OOP(Object Oriented Programming) works. The program i write is about the propagation of sound waves.
I believe you know this formula of sound v = 2x/t .
It's used to find
/*
* This class just construct the formulae for solving
* speed of sound
* distance of sounde
* and time sound take to reach back it's
* Notice that the class doesn't contain a main method
*/
public class Sound
{
// Inatialise our varibles
public double v;
public double x;
public double t;
// method for calculating speed of sound
public double speed(double x, double t)
{
v = (2*x)/t;
return v;
}
// method for calculatin distance of sound
public double distance(double v, double t)
{
x =(v*t)/2;
return x;
}
// method for calculating time
public double time(double v, double x)
{
t = (2*x)/v;
return t;
}
}
Next, we create the file SoundDrive.java which will contain the main method. You must also save the two files(i.e Sound.java and SoundDrive,java) in the same directory.
In the SoundDrive.java you will notice how we create and object calc using our Sound class, after creating the object we are able to access it;s methods and variables.
Below is the Source code for the SoundDrive.java
import java.util.Scanner;
public class SoundDrive
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in); // construct input
Sound calc = new Sound(); //create obkect of class sound
String get;
System.out.println("This program calculate Speed of sound, distance of the"
+ " sound and the time sound take to echo.\n How to work with it, enter "
+ "v to calculate sound speed, enter x to calculate distance of sound\n or enter t"
+ " to calculate time.");
System.out.print("Enter V, X or T or enter any key to exit: "); // prompt user for selection
get = input.nextLine(); //
if (get.equalsIgnoreCase("v"))
{
System.out.print("Enter Distance: ");
double dst,tm;
dst = input.nextDouble();
System.out.print("Enter Time: ");
tm = input.nextDouble();
System.out.println("The speed of sound = "+calc.speed(dst, tm)+"m/s");
}
else if (get.equalsIgnoreCase("x"))
{
System.out.print("Enter Speed: ");
double spd,tm;
spd = input.nextDouble();
System.out.print("Enter Time: ");
tm = input.nextDouble();
System.out.println("The distance X = "+calc.distance(spd, tm)+"m");
}
else if (get.equalsIgnoreCase("t"))
{
System.out.print("Enter Speed: ");
double spd,dst;
spd = input.nextDouble();
System.out.print("Enter Distance: ");
dst = input.nextDouble();
System.out.println("The time T = " +calc.distance(spd, dst)+"s");
}
}
}
This is small example about the concept of OOP in java. Have fun with it.
I believe you know this formula of sound v = 2x/t .
It's used to find
- v which is speed of the sound in meters per second m/s.
- x which is the distance of the sound in meters m,
- t which is time in seconds s/
/*
* This class just construct the formulae for solving
* speed of sound
* distance of sounde
* and time sound take to reach back it's
* Notice that the class doesn't contain a main method
*/
public class Sound
{
// Inatialise our varibles
public double v;
public double x;
public double t;
// method for calculating speed of sound
public double speed(double x, double t)
{
v = (2*x)/t;
return v;
}
// method for calculatin distance of sound
public double distance(double v, double t)
{
x =(v*t)/2;
return x;
}
// method for calculating time
public double time(double v, double x)
{
t = (2*x)/v;
return t;
}
}
Next, we create the file SoundDrive.java which will contain the main method. You must also save the two files(i.e Sound.java and SoundDrive,java) in the same directory.
In the SoundDrive.java you will notice how we create and object calc using our Sound class, after creating the object we are able to access it;s methods and variables.
Below is the Source code for the SoundDrive.java
import java.util.Scanner;
public class SoundDrive
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in); // construct input
Sound calc = new Sound(); //create obkect of class sound
String get;
System.out.println("This program calculate Speed of sound, distance of the"
+ " sound and the time sound take to echo.\n How to work with it, enter "
+ "v to calculate sound speed, enter x to calculate distance of sound\n or enter t"
+ " to calculate time.");
System.out.print("Enter V, X or T or enter any key to exit: "); // prompt user for selection
get = input.nextLine(); //
if (get.equalsIgnoreCase("v"))
{
System.out.print("Enter Distance: ");
double dst,tm;
dst = input.nextDouble();
System.out.print("Enter Time: ");
tm = input.nextDouble();
System.out.println("The speed of sound = "+calc.speed(dst, tm)+"m/s");
}
else if (get.equalsIgnoreCase("x"))
{
System.out.print("Enter Speed: ");
double spd,tm;
spd = input.nextDouble();
System.out.print("Enter Time: ");
tm = input.nextDouble();
System.out.println("The distance X = "+calc.distance(spd, tm)+"m");
}
else if (get.equalsIgnoreCase("t"))
{
System.out.print("Enter Speed: ");
double spd,dst;
spd = input.nextDouble();
System.out.print("Enter Distance: ");
dst = input.nextDouble();
System.out.println("The time T = " +calc.distance(spd, dst)+"s");
}
}
}
This is small example about the concept of OOP in java. Have fun with it.
Saturday, 12 April 2014
A SIMPLE JAVA GUI CALCULATOR
Below is the source code of a simple Java GUI Calculator that I programmed couple of days ago.
This is the Snapshot of the calculator
This is the Snapshot of the calculator
The calculator works with two text fields the (i.e for first number and second number), I also used uneditable third text field to display the result. Entering a given numbers in the two text fields and clicking an arithmetic operator button will display the result.
This is the Source Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Calculator extends JFrame
{
public JTextField text = new JTextField(10);
public JTextField text2 = new JTextField(10);
public JTextField rslt = new JTextField(10);
public int num = 11;
public int number;
public Calculator()
{
JFrame cover = new JFrame("My App");
cover.setLayout(new FlowLayout());
cover.setSize(260, 200);
cover.setTitle("Maitalata's Calc.");
cover.setVisible(true);
cover.add(new JLabel("First Numbber "));
cover.add(text);
cover.add(new JLabel("Second Number"));
cover.add(text2);
cover.add(new JLabel("Result"));
cover.add(rslt);
rslt.setEditable(false);
JButton b = new JButton("/");
cover.add(b);
b.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent e){
String first = text.getText();
String second = text2.getText();
first.trim();
second.trim();
int a;
int b;
int c;
a = Integer.parseInt(first);
b = Integer.parseInt(second);
c = a / b;
rslt.setText(c+"");
}
} );
JButton c = new JButton("+");
cover.add(c);
c.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent e){
String first = text.getText();
String second = text2.getText();
first.trim();
second.trim();
int a;
int b;
int c;
a = Integer.parseInt(first);
b = Integer.parseInt(second);
c = a + b;
rslt.setText(c+"");
}
} );
JButton d = new JButton("-");
cover.add(d);
d.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent e){
String first = text.getText();
String second = text2.getText();
first.trim();
second.trim();
int a;
int b;
int c;
a = Integer.parseInt(first);
b = Integer.parseInt(second);
c = a - b;
rslt.setText(c+"");
}
} );
JButton st = new JButton("x");
cover.add(st);
st.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent e){
String first = text.getText();
String second = text2.getText();
first.trim();
second.trim();
int a;
int b;
int c;
a = Integer.parseInt(first);
b = Integer.parseInt(second);
c = a * b;
rslt.setText(c+"");
}
} );
JButton e = new JButton("Clear");
cover.add(e);
e.addActionListener( new ActionListener() {
@Override
public void actionPerformed(ActionEvent e){
text.setText(null);
text2.setText(null);
rslt.setText(null);
}
} );
}
public static void main(String args[])
{
Calculator nw = new Calculator();
}
}
Saturday, 29 March 2014
Strong Password
Strong password is the padlock to your online accounts, you should as much as possible try to make your password very secure. Below is the list of some frequently used password that you should avoid using.
- 123456
- password1
- 1password
- 654321
- 000000
- Your first name or surname
- Your phone number
- Your favourite stuff name.
- And any word that can be guessed by someone who knows you.
Tuesday, 18 March 2014
PHISHING
What is Phishing?
Phishing is a method that is employed by computer crackers to get your details, especially login details, such as usernames and passwords. The cracker will create a page similar to the one that you use to login into a particular online system such as Facebook, and send it to you, usually as a link. After clicking the link, the victim is taken to the fake page. The fake page will look exactly like the original one, except that, after you have entered your login details, they will be sent directly to the attacker. and the attacker will then redirect you to another page. Phishing has proved to be effective way for attackers to get people's login details.
How to avoid phishing.
Phishing is a method that is employed by computer crackers to get your details, especially login details, such as usernames and passwords. The cracker will create a page similar to the one that you use to login into a particular online system such as Facebook, and send it to you, usually as a link. After clicking the link, the victim is taken to the fake page. The fake page will look exactly like the original one, except that, after you have entered your login details, they will be sent directly to the attacker. and the attacker will then redirect you to another page. Phishing has proved to be effective way for attackers to get people's login details.
How to avoid phishing.
- Never click on strange links
- If you have been redirected from some sites into a social network site, such as Facebook, and the page requires you to enter your login details, check your browser's address bar, to see if it is indeed the original Facebook address.
Monday, 17 March 2014
HOW TO FIND IP ADDRESS OF A WEBSITE USING COMMAND PROMPT
Did you know that you can use your PC's windows command prompt to find the IP address of any website? The process us very easy. Just make sure you have internet access on your PC, then open windows command prompt. If you don't know how to open the windows command prompt, just follow the steps below.
- Click on Windows START Button at the lower left corner of your PC(Note: If you have changed the appearance of your taskbar, the START button will not be at this location. )
- After you have clicked on the START button, then write "cmd" without the quotation marks in the search program text bar.
- Click at the program that appear with the name "cmd".
- A black window will appear, which is the windows command prompt.
Wednesday, 5 March 2014
JAVA IF CONDITION
The following program demonstrates how java If...else statement works. The program imports java.util.Scanner package, which will handle the user input by scanning the inserted variable. First, the program ask for the year Nigeria got it's independence, if the user guesses correctly by putting '1960', the program will print "correct answer, you are genius", otherwise, the program will print "wrong answer, please try again." Also if the user luckily insert '1959', the program will print "You are almost correct, keep trying.". I just write the program to demonstrate how java if...else condition statement is used.
import java.util.Scanner;
public class BRRead{
public static void main(String args[]){
int a;
Scanner in = new Scanner(System.in);
System.out.println("Enter The year Nigeria got it's independence ");
a = in.nextInt();
if (a==1960)
{
System.out.println("Correct answer, you are genius!!!");
}
else if(a==1959)
{
System.out.println("You are almost correct, keep trying.");
}
else
{
System.out.println("Wrong answer, please try again.");
}
}
}
if you have any java IDE such as Netbeans, Jgrasp or Eclipse, just copy the above program and paste it into your IDE and save the file as BRRead and then compile it, remember java is case-sensitive.
import java.util.Scanner;
public class BRRead{
public static void main(String args[]){
int a;
Scanner in = new Scanner(System.in);
System.out.println("Enter The year Nigeria got it's independence ");
a = in.nextInt();
if (a==1960)
{
System.out.println("Correct answer, you are genius!!!");
}
else if(a==1959)
{
System.out.println("You are almost correct, keep trying.");
}
else
{
System.out.println("Wrong answer, please try again.");
}
}
}
if you have any java IDE such as Netbeans, Jgrasp or Eclipse, just copy the above program and paste it into your IDE and save the file as BRRead and then compile it, remember java is case-sensitive.
Wednesday, 29 January 2014
HTML FORM
The best way to display your HTML form is to insert it inside a table, like this:
<! DOCTYPE html>
<head>
<title>FORM</title>
</head>
<body>
<form action="submit.php" method="post">
<table border="0">
<tr>
<td> Username </td><td>< input type="text" name="username"></td>
</tr>
<tr>
<td> Password </td>< input type="password" name="username"></td>
</tr>
<tr><td><input type="submit" value="LOGIN"></td>
</tr>
</table>
</form>
</body>
</html>
When you load the form in this way you will see that it appears without the table borders. and the form will look good.
<! DOCTYPE html>
<head>
<title>FORM</title>
</head>
<body>
<form action="submit.php" method="post">
<table border="0">
<tr>
<td> Username </td><td>< input type="text" name="username"></td>
</tr>
<tr>
<td> Password </td>< input type="password" name="username"></td>
</tr>
<tr><td><input type="submit" value="LOGIN"></td>
</tr>
</table>
</form>
</body>
</html>
When you load the form in this way you will see that it appears without the table borders. and the form will look good.
Saturday, 11 January 2014
WEB DESIGN
Web design is quite easy, to start creating website, you just need to learn HTML, PHP, CSS, JAVASCRIPT and SQL.
HTML which stands for Hyper Text Markup Language is a markup language used to create website that are displayed by browsers. HTML is not a programming language, it's a markup language, it is enclosed inside tags(i.e. < and >). HTML is very easy to learn, you can learn the core HTML aspects in just a day, it just depends on your dedication.
PHP is a server-side scripting language that enables you to create dynamic websites, it;s a powerful programming language that supports object orientation. PHP is also executed on the server, but you can embed it inside HTML pages/
CSS which stands for cascading-style sheet is another web development language that lets you create attractive websites, CSS is just like a cosmetic to websites.
JAVASCRIPT is a programming language that enables a web developer to create dynamic websites, the difference between javascript and PHP is that while the latter is executed on the server, javascript is executed on the browser, it helps a web developer to reduce the traffic on his server.
SQL stands for Structured Query Language lets a web developer to interact with his database.
HTML WITH JAVASCRIPTY
Here is a simple way to display a text in a browser using using Javascript
<!DOCTYPE html>
<head>
<title>Home</title>
</head>
<body bgcolor='gray'>
<script>
document.write("I welcome you to my website, have a nice day");
</script>
</body>
</html>
The above piece of JavaScript code will display a message "I welcome you to my website, have a nice day" when the browser loads the page.
<!DOCTYPE html>
<head>
<title>Home</title>
</head>
<body bgcolor='gray'>
<script>
document.write("I welcome you to my website, have a nice day");
</script>
</body>
</html>
The above piece of JavaScript code will display a message "I welcome you to my website, have a nice day" when the browser loads the page.
Subscribe to:
Posts (Atom)