You are here: difficulties with include and writting to files « PHP Programming Language « IT news, forums, messages
difficulties with include and writting to files

Posted by Robizzle on 11/16/59 11:28

I'm working on a very simple script that logs the ip address, time of
hit, and os/browser information and currently it works every time. The
problem is getting the script included into my html document (so I can
log everyone that visits that page.) Here is my code and how the files
are organized:

I know some of the code is probably sloppy, these are literally the
first php files i've written and I just started yesterday from
w3school's tutorial.

root/index.html
root/php/hitcounter.php
root/php/hits.wordpad
root/php/browser.php
root/includetest.php

hitcounter.php:
<?php

require_once('browser.php');
$br = new Browser;

$filename = 'hits.wordpad';
$today = date("n.j.Y H:i:s");

if (is_writable($filename)){
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}

/* Write the following:
Month.Day.Year[space]Hour:Minute:Second[newline]
IP Address[newline]
Operating System[space]Browser[space]Browser Version[newline]
*/
if (fwrite($handle, $today) && fwrite($handle, "\n") &&
fwrite($handle, $_SERVER["REMOTE_ADDR"]) && fwrite($handle, "\n") &&
fwrite($handle, $br->Platform) && fwrite($handle, " ") &&
fwrite($handle, $br->Name) && fwrite($handle, " ") && fwrite($handle,
$br->Version) && fwrite($handle, "\n") && fwrite($handle, "\n") ==
FALSE){
exit;
}
fclose($handle);
}
else {
echo "The file $filename is not writable";
}
?>

includetest.php:
<?php

$path = './php/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
include ('hitcounter.php');

?>

If I open my browser and directly go to
http://.../root/php/hitcounter.php everything works fine. The file
gets appended with my IP and browser information as it should. If I go
to http://.../root/includetest.php I get an error output "The file
hits.wordpad is not writable". This is odd because that particular
error message only appears in hitcounter.php ... so I know that that
code is executing. But yet, that code never has a problem executing
when I visit the php file directly.

Lastly, assuming someone can get this solved for me, my next question
is about including the hitcounter in an html document. I was thinking
the following would work:
<?php
include 'php/hitcounter.php'
?>
However, when I tried this with a similar script, it appears to do
nothing and I can view the page source of my html file and see the php
code (shouldn't the server replace that block before sending the html
file out?)

I have checked file and folder permissions on my server (as I have had
problems with write protected files) but can't seem to figure this one
out. I have looked at all the resources I know of and run many
searches trying to solve this without wasting you guy's time, but alas,
I come for help.

Thanks in advance,
Rob

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация