Does anyone know if you could use PHP to grab info from a user. Data like perhaps comp specs or browser type or ip and stuff? Or does anyone know if there's something that you can use to see what/where people are viewing your site from/with?
Thanks.
Yes you can get a persons IP
Yes you can get their browser type
Im pretty sure you can get their operating system too.
Yes, you can get all type of those information. This is what the $_SERVER variable is for. Take a look at this page for further info: http://tr2.php.net/manual/en/reserved.variables.php
And also don't forget that clients can "lie" about their browsers: the header can be altered.
There are many, many scripts for that at http://www.hotscripts.com.
No need to reinvent the wheel all the time. 
Lolz, yeah. I'm notorious for that..
Thanks for the help guys!
I can't seem to find a code that caps the IP.. Help? (again)
This is used to display there IP
| Code: |
<?
echo "Your IP: " . $_SERVER['REMOTE_ADDR'];
?> |
If you want to record there ip add this
| Code: |
<?php
function logIP()
{
$ipLog="logfile.htm"; // Your logfiles name here (.txt or .html extensions ok)
$register_globals = (bool) ini_get('register_gobals');
if ($register_globals) $ip = getenv(REMOTE_ADDR);
else $ip = $_SERVER['REMOTE_ADDR'];
$date=date ("l dS of F Y h:i:s A");
$log=fopen("$ipLog", "a+");
if (preg_match("/\bhtm\b/i", $ipLog) || preg_match("/\bhtml\b/i", $ipLog))
{
fputs($log, "Logged IP address: $ip - Date logged: $date<br>");
}
else fputs($log, "Logged IP address: $ip - Date logged: $date\n");
fclose($log);
}
// Place the below function call wherever you want the script to fire.
logIp();
?> |
well ive made a tutorial for logging ip's into a .txt file here it is
______________________________________________________
| Quote: |
1) create an index.php or w/e you want to call the page (mine is index.php)
2) here is the code:
| Code: | <?php
$domain = $_SERVER['REMOTE_ADDR'];
$f = fopen("ip.txt","a");
fwrite($f, $domain);
fwrite($f, "<br>");
fclose($f);
print("This Is oMejA's IP Logger, your ip: $domain has been logged");
?> |
4) dont panic ill explain this code.
$domain = $_SERVER['REMOTE_ADDR']; - gets the page viewers ip
$f = fopen("ip.txt","a"); - opens the text file for writing.
fwrite($f, $domain); - writes their ip in the text file..
fwrite($f, "<br>"); writes something else in the text file (will explain in a sec)
fclose($f); closes the file
print("This Is oMejA's IP Logger, your ip: $domain has been logged"); - Says on the page that ur ip was logged and by putting $domain it shows their ip
5)make a file called ip.txt (note if hosted on a linux server, chmod this file to 777 if your
hosting this from a windows comp then dont worry.
6)make iplist.php
7) put this code in iplist.php
| Code: | <?php
include("ip.txt")
?> |
now this if you recall above,,
| Quote: | | fwrite($f, "<br>"); |
that code adds <br> to the text file so when you open iplist the ips go down as a list, rather than a line
9) and thats it any questions/comments fungoku@hotmail.com |
Wow! Much thanks guys. I appreciate it lots 
The following PHP script finds the browser and operating system of the user. The browser feature is used on the main page of E-Lyrics to tell the user compatibility issues at the top of the page.
http://frihost.pastebin.com/709255
| mathiaus wrote: |
| Please do not post large pieces of code and if you must at least use code tags |
| DanielXP wrote: |
If you want to record there ip add this
| Code: | <?php
function logIP()
{
$ipLog="logfile.htm"; // Your logfiles name here (.txt or .html extensions ok)
$register_globals = (bool) ini_get('register_gobals');
if ($register_globals) $ip = getenv(REMOTE_ADDR);
else $ip = $_SERVER['REMOTE_ADDR'];
$date=date ("l dS of F Y h:i:s A");
$log=fopen("$ipLog", "a+");
if (preg_match("/\bhtm\b/i", $ipLog) || preg_match("/\bhtml\b/i", $ipLog))
{
fputs($log, "Logged IP address: $ip - Date logged: $date<br>");
}
else fputs($log, "Logged IP address: $ip - Date logged: $date\n");
fclose($log);
}
// Place the below function call wherever you want the script to fire.
logIp();
?> |
|
These are the errors I get:
| Code: |
Warning: fopen(add.txt): failed to open stream: Permission denied in /home/ghostfac/domains/offline.frih.net/public_html/index.php on line 126
Warning: fputs(): supplied argument is not a valid stream resource in /home/ghostfac/domains/offline.frih.net/public_html/index.php on line 132
Warning: fclose(): supplied argument is not a valid stream resource in /home/ghostfac/domains/offline.frih.net/public_html/index.php on line 134 |
And these are the errors I get with [FUN]goku's code: | Code: |
Warning: fopen(add.txt): failed to open stream: Permission denied in /home/ghostfac/domains/offline.frih.net/public_html/index.php on line 117
Warning: fwrite(): supplied argument is not a valid stream resource in /home/ghostfac/domains/offline.frih.net/public_html/index.php on line 118
Warning: fwrite(): supplied argument is not a valid stream resource in /home/ghostfac/domains/offline.frih.net/public_html/index.php on line 119
Warning: fclose(): supplied argument is not a valid stream resource in /home/ghostfac/domains/offline.frih.net/public_html/index.php on line 120
|
did you chmod the files to 777? 
yeah make sure to chmod 777 the ip.txt if u alredy havent done so.... unless your running it from a windows comp
Er, what's chmod? And I'm hosting the site from frihost. How would I know if it's running on a pc or linux?
Edit: Oh, the permission column? Lemme try it..
| Ghost Face wrote: |
| Er, what's chmod? And I'm hosting the site from frihost. How would I know if it's running on a pc or linux? |
It's running on Linux.
To chmod, right-click on the file in your ftp client, select Properties, and you will see it.
Yeah, I figured it out
Ok, [FUN]goku's code works but the big fat code won't and it gives me this error code: | Code: |
Parse error: syntax error, unexpected T_STRING in /home/ghostfac/domains/offline.frih.net/public_html/index.php on line 118
|
But I can't find a part in the code that says anything about a T_STRING. Help (again again)!
Edit: Ok, another screw up.. This is the code I'm using to put the captured OS and browser type into a *.txt file. What am I doing wrong? (I went to the file and it just shows spaces instead of the value of the var)
| Code: |
//put browser and os type in file
$f = fopen("browseos.txt","a");
fwrite($f, "Browser: " . $this->Name . "<br>");
fwrite($f, "Version: " . $this->Version . "<br>");
fwrite($f, "Platform: " . $this->Platform . "<br>");
fwrite($f, "AOL: " . $this->AOL . "<br>");
fwrite($f, "<br>");
fclose($f);
|
Another Edit: Ok, I changed the files to *.html so the <br> part works..
Silly me!
The REMOTE_ADDR needs to be enclosed in quotes.
So replace
| Code: |
if ($register_globals) $ip = getenv(REMOTE_ADDR);
else $ip = $_SERVER['REMOTE_ADDR']; |
with
| Code: |
if ($register_globals) $ip = getenv('REMOTE_ADDR');
else $ip = $_SERVER['REMOTE_ADDR']; |
I still get an error 
is getenv('REMOTE_ADDR'); a function or should it be $getenv('REMOTE_ADDR');
getenv() is a function.
The function 'getenv' does not work if your Server API is ASAPI (IIS).
So, try to don't use getenv('REMOTE_ADDR'), but $_SERVER["REMOTE_ADDR"].
Thus, the code:
| Code: |
$ip = $_SERVER["REMOTE_ADDR"];
|
I still get the same error even after I changed the code to | Code: |
$ip = $_SERVER["REMOTE_ADDR"];
|
It keeps on saying something about T_STRING..
I think the error is from the code used to get the OS and Browser type.
Could you show us the whole source of your index.php, because your error is now on line 332. As we don't know what line 332 really contains, we can not really help you. We can just guess...
Error Message: | Code: |
Parse error: syntax error, unexpected T_STRING in /home/ghostfac/domains/offline.frih.net/public_html/index.php on line 127 |
Source *drum roll*: http://frihost.pastebin.com/714475
| mathiaus wrote: |
| If posting large pieces of code, please use a pastebin. |
For those who haven't looked at the pastebin, here's the line of code:
| Code: |
| $ipLog="add2.html"; // Your logfiles name here (.txt or .html extensions ok) |
What's giving me this notorious T_STRING error? Help!
Postscript: Sorry Mathiaus
| Ghost Face wrote: |
Error Message:[code]
Source *drum roll*: http://frihost.pastebin.com/714475
What's giving me this notorious T_STRING error? Help!
Postscript: Sorry Mathiaus |
i have checked your code and i didn't find any error in it, and my browser didn't give me any T_STRING error.
please check your code once more and make sure there's no ; sign left behind.
Yeah, I removed the code that wasn't working since noone was looking at this thread anymore, but now that someone is I will!