GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 19-May-2006, 02:12
Johnny Johnny is offline
New Member
 
Join Date: May 2006
Posts: 27
Johnny is on a distinguished road

Problem with a small piece of referrer code.


referrers.php
PHP Code:

<?PHP

// $mydomain[0] = "website.net";
// $mydomain[1] = "www.website.net";

   
   $refurl = $HTTP_REFERER;
   $cururl =  "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
   $IP = $REMOTE_ADDR;

   $fullline =  $refurl . " " .  $cururl . " " . $IP . "\n";
   
   $myFile = "referrers.txt";
   $f = fopen($myFile,"a");
   fwrite($f, $fullline);
   fclose($f); 


?>


Ignore the $mydomain at the top, I was going to add some kind of filtering for referrers from the same domain, but couldn't even get this to work yet.

If I echo it, instead of writing it to a file it seems to work. I made sure that referrers.php was CHMOD'd to 666, but it still didn't write it to a file. I'm not sure what I am doing wrong, as I said I tried echoing it and it worked fine. But writing to a file wont, even if I use a literal string for the first argument or fopen() instead of a variable. Or if I use single quotes for the second parameter 'a' or double quotes "a". I even tried creating the text file and placing it in the directory incase the problem was creating the file.

Any help would be great.
Last edited by LuciWiz : 19-May-2006 at 02:57. Reason: Please insert your PHP code between [php] & [/php] tags
  #2  
Old 19-May-2006, 02:20
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: Problem with a small piece of referrer code.


This is definitely a permission issue. Is this script on a Linux/Unix machine?

Are you sure the script (referrers.php) has the required permission to create / write to the LOG file?

When I write scripts that create or write to a text file, I usually create a directory just to store these log / data / text files and assign the web server (e.g. nobody or apache) read, write and execute permissions for that folder.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #3  
Old 19-May-2006, 02:29
Johnny Johnny is offline
New Member
 
Join Date: May 2006
Posts: 27
Johnny is on a distinguished road

Re: Problem with a small piece of referrer code.


It is in a separate folder (it was before) but I chmod'd the folder and all subfolders/files to 777. It is now working as it should be. Thank you very much
  #4  
Old 19-May-2006, 02:33
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: Problem with a small piece of referrer code.


I am glad...

I am curious now. Are you only interested in the referrers for your web pages or is this script part of a larger data gathering script?

The reason I ask: if you're only interested in the referrer information, you should really consider parsing your web server's log file for the information instead.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #5  
Old 19-May-2006, 03:15
Johnny Johnny is offline
New Member
 
Join Date: May 2006
Posts: 27
Johnny is on a distinguished road

Re: Problem with a small piece of referrer code.


Just referrer data, IP isn't really important but I put it there incase at a future date I decide I want it. I was just thinking along the lines of referring site (url to be specific) current url it directs to, and the number of hits. So if the same referring url directs to the same page 2 times it would have a little 2 in brackets maybe next to it. But then what if it is the same referring page but a different page it directs to? Would I class that as a separate hit or the same because it is from the same referrer. Also I would need to add some kind of filtering to stop referrals from my own domain.

So I want to keep it quite basic but do it in a certain way so it is quite precise. I couldn't see the access log files on the FTP, but in the control panel there was a log manager. I took a little look and could see access_log which was 98mb, I downloaded it and it contained:
IP -- [Date/Time (what seems to be timezone info like -0700)] The type of request like POST or GET HTTP etc and user agent.

This seems to be for other websites not just mine though, perhaps the log is shared between the other sites that are hosted on this server as it is shared hosting. There was also a access_log.processed which was only about 2KB xferlog_regular.processed and non processed, which just contains details of what I have been transfering through FTP. And an error_log.

I couldn't see any details of referrers in any of the files that I looked in
  #6  
Old 19-May-2006, 03:27
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: Problem with a small piece of referrer code.


If you can get the correct information from your web host, I can help you write a simple script that you can use to extract the referrer information from the log file.

The correct information required is:
  • The path to your web site access log file. It just needs to have READ permission for everyone (so your script can read the file).
  • If you can paste a couple of lines from this log file, it will help us a lot. (you can edit any data that you consider private but keep the structure intact)

You could have a cronjob run the script every few minutes and update a database or something.

This should be a fun little project for the weekend!
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #7  
Old 19-May-2006, 03:50
Johnny Johnny is offline
New Member
 
Join Date: May 2006
Posts: 27
Johnny is on a distinguished road

Re: Problem with a small piece of referrer code.


I don't know the location of the file, but I can always download the file to my PC from the control panel. I was thinking I could filter the file for my domain so I don't get any of the data from the other sites sharing the server. That doesn't seem possible now though because the only places my domain appears are when it is the referrer.

IP - - [Date/Time -/+TimeZone] "GET/POST /webpage.extension HTTP/1.1" 200 (OK reply?) (not sure what the next number is) "http://website.com/page.php" <<--Referring page. "user agent browser info"
Code:
127.0.0.1 - - [18/May/2006:20:04:52 -0700] "GET /usersearch.php HTTP/1.1" 200 1448 "http://www.website.net/page1.php" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)" 127.0.0.1 - - [18/May/2006:20:17:34 -0700] "GET /browse.php HTTP/1.1" 200 1648 "http://www.website.net/page2.php" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)" 127.0.0.1 - - [18/May/2006:20:19:14 -0700] "GET /details.php?id=3&hit=1 HTTP/1.1" 302 26 "http://www.website.net/page1.php" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)" 127.0.0.1 - - [18/May/2006:20:19:14 -0700] "GET /page2.php HTTP/1.1" 200 1566 "http://www.website.net/page1.php" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)" 127.0.0.1 - - [18/May/2006:20:19:16 -0700] "GET /edit.php?id=3 HTTP/1.1" 200 5619 "http://www.website.net/details.php?id=3" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)" 127.0.0.1 - - [18/May/2006:20:19:26 -0700] "POST /delete.php HTTP/1.1" 200 2284 "http://www.website.net/edit.php?id=3" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)" 127.0.0.1 - - [18/May/2006:20:19:30 -0700] "GET / HTTP/1.1" 304 - "http://www.website.net/page3.php" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"

Even though I'm not very good at data parsing in any language, I don't think that would be the biggest problem right now. It would probably be the access_log because it is mixed. Maybe I should continue work on the referrer logging script, as I could do with learning PHP anyway.

What are your thoughts?

-EDIT- If I don't reply right away, I'm not ignoring you, it is 9:48 am and I haven't slept yet, so I may be off to bed, and view this when I wake up, just so you know
  #8  
Old 19-May-2006, 04:01
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: Problem with a small piece of referrer code.


One log file for all the domains? How odd!

Did you ask your web host if one exists just for your domain? I am almost certain this is available somewhere. But in case it's not, you may consider moving when you can afford to move because that's just plain weird.

Back to the script you are writing:

Sure, you can and should proceed with your work on this script if you only want to learn. I will not discourage you.

And if we wrote the script to parse your log file, you will also learn quite a bit about PHP (and the added bonus of having them work in the command line, i.e. not via a browser).
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #9  
Old 19-May-2006, 04:04
Johnny Johnny is offline
New Member
 
Join Date: May 2006
Posts: 27
Johnny is on a distinguished road

Re: Problem with a small piece of referrer code.


That would be great to learn how to run PHP files from the command line, I was thinking of setting up a HTTPD with PHP on my PC just to learn that before. I wouldn't be able to do it with my host though I don't think as I don't have shell/ssh access. Unless it can be executed via another PHP file through the browser hehe, but that kind of takes the point away I guess.

I have wanted to learn PHP for a while, it seems such a powerful language, and so versatile.
  #10  
Old 19-May-2006, 04:08
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: Problem with a small piece of referrer code.


It's not necessary for you to have (remote) access to your server. You can set it up as a cronjob and it will be run every few minutes.

You can set up a cronjob, can't you?
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Here it is again! 35% - 40% off For Life! my-e-space Web Hosting Advertisements & Offers 0 20-Apr-2006 15:48
Problem with porting of Linux code to Windows, FORTRAN/C. stormlab C Programming Language 2 15-Oct-2005 04:53
Problem with porting of Linux code to Windows, FORTRAN/C. stormlab Computer Software Forum - Linux 0 14-Oct-2005 13:25
Problem with int mixed with char,... leitz C++ Forum 17 07-Dec-2004 21:56
This is a small snippet from a much larger piece. Tang_Quester Open Discussion Forum 1 19-Mar-2004 02:17

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:29.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.