I have a variable that I want to send to another file to be echoed out to the screen. I tried sessions but no luck. I was searching and the searches say to use GET or POST but they aren’t working either. I don’t get anything when I try it, but then it could be wrong code. I have a hit counter that I am working on. The idea is to get the number from a file and then send that number to a different page to be seen. I want it like this so that no one else but me can see the numbers. Here is the hit counter that works. This will display the number to the screen if you make an index.php and an empty file called reader.txt.
$filename= “reader.txt” ;
$fd = fopen ($filename , “r”) or die (“Can’t open $filename”) ;
$fstring = fread ($fd , filesize ($filename)) ;
$fd = fopen ($filename , “w”) or die (“Can’t open $filename”) ;
$fcounted = $fstring + 1 ;
$fout= fwrite ($fd , $fcounted ) ;
I don’t know why the code is written this way, I have been following a tutorial. What I want to do is be able to use $fstring in another page. I want to be able to include this code in one page without it showing the results on that particular page. I think this makes sense.
This reply has been reported for inappropriate content.
well the simplest sollution I was able to figure out was to put the code that reads the file into the other page that I want to beable to use the variable. Then I just subtracted one from the count and all was good. But I want to know the real way to do it for future use. There has to be a better way.