web counters Php Training Online - Wordpress Beginner Tutorial - Wordpress Tutorials - Php Mysql Example

 

| Web |
| Image |
| Video |
| News |
| Sports |
| Audio |
| Wiki |
| PDF |
| iTunes |

Thursday, 11 April 2013

Find IP Address in PHP


Here now learn the script of to find ip address in php of visitor which visit on website.

To store Visitor ip addres in PHP has syntax :-
1
$_SERVER[‘REMOTE_ADDR’]     // return visitor ip address
When a ip address has been received then now need text file to enter in it by using the
syntax fwrite() function
1
$myipaddress = $_SERVER['REMOTE_ADDR']."\r\n";
In above codes first declare a variable which can pick IP address of  Visitor. One thing remember if you are testing or working on localhost server then naturally it return Local IP 127.0.0.1
First, we will use a variable to store the ip address. If you are working on a localhost environment, it will return 127.0.0.1
1
$myipaddress = $_SERVER['REMOTE_ADDR']."\r\n";
Now time to store visitor IP address in file using the PHP functions fopen() and fwrite(). 
Use below codes for that :
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// store visitor ip address
$myipaddress = $_SERVER['REMOTE_ADDR']."\r\n";

// Log file name which store all ip address
$ipfile = 'logdata.txt';

// store visitor data by opening log file
$ipfp = fopen($ipfile, 'a');

fwrite($ipfp, $myipaddress);

fclose($ipfp);
These codes produce the output like as below in our log file:
127.0.0.1
127.0.0.1
127.0.0.1
127.0.0.1
We can also approve more this script with help of to enter other PHP funcations like as browser information and visitor’s visited page.
For that we need miner changes in our pre-written PHP script codes.
Use below codes for that :
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
// store visitor ip address
$myipaddress = $_SERVER['REMOTE_ADDR']."\r\n";

// visited page name
$page = $_SERVER['SCRIPT_NAME'];

// browser detail
$brow = $_SERVER['HTTP_USER_AGENT'];

// Log file name which store all ip address
$ipfile = 'logdata.txt';

// store visitor data by opening log file
$ipfp = fopen($ipfile, 'a');

fwrite($ipfp, $myipaddress);

fclose($ipfp);
These codes produce the output like as below in our log file:
127.0.0.1 - /product.html Mozilla 19.0 (Windows NT)
127.0.0.1 - /product.html Mozilla 19.0 (Windows NT)
127.0.0.1 - /product.html Mozilla 19.0 (Windows NT)
127.0.0.1 - /product.html Mozilla 19.0 (Windows NT)
Enjoy :) you have done!

Tuesday, 3 April 2012

using php with html

I writing this post with the view of that you familiar with “what is HTML Page and basic PHP?”. For run PHP codes inside PHP also require a server on your local machine which is a publish in our blog. So we know that HTML is a base of web development where developer can present content in fashionable way for website. Well form formatted of HTML pages give benefits to spread world-wide which will we cover later. HTML pages have basic structure to present contents. There are some different area in HTML which use for different purpose. Now given below is basic structure of HTML page.
<html>
<head>
<title>This is the title shown above the menu bar on my browser</title>
</head>
 
<body>
I wish I knew how to write PHP in HTML files...
</body>
 
</html>
Now we come to our main aim is use of php. We can combine HTML and PHP in same page of website. In above section we learn basic structure of HTML Page. Look “How merge PHP codes in HTML?”
<html>
<head>
<title>This is the title shown above the menu bar on my browser</title>
</head>
 
<body>
<?php
  print "I know how to write PHP!";
?>
 
<b>Perhaps I'll be lazy and write more php.</b>
 
<?php print "No way!  PHP is cool!<br />"; ?>
</body>
 
</html>
Now we saw “How combine to language contents?”. <?php show the start of php working area and ?> show end of php codes. So we can easly start php area any where in html page according to requirement. You can put your codes inside of  <?php your statement goes here…… ?> . if you type your code out side of <?php ?>  it not working and html page is taking it as simple contents. Because to work with php need to define its working area. So then php language trace and under of what command type and there contents.

 

Web Hosting