When posting PHP code, please use the board's
..
bbcode tags (instead of the generic CODE tags) as they make your code much easier to read and analyze.
1) Understood I will do so in the future.
In your if() statement, you're using the '=' operator, which is the assignment operator. In other words, your if() statement is actually assigning a value to $userlogfile rather than comparing it's value (which is done with a comparison operator, such as '=='). See the manual page operators.comparison for more info.
2) I did not know that, thank you for clearing that up.
Speaking of the if() statement... where is $userlogfile ever defined?
3) I fiddled with my code some after posting, and added
$userlogcountfile="../logs/" . $username . "logon.txt";
just above the //read logon file
How is checking if a (presently undefined) variable is equal to the NULL value giving you any sort of "file detection" ? Surely you don't expect PHP to automagically understand what you meant to do?
Instead, look at using file_exists() to check if a file already exists or not.
4) I don't know....I should have known better. I will do that in the future. I will be adding automagically to the fun section of my vocab though.
Seems like your logic could be optimized to make the code easier to understand as well as more efficient.
5) Yes i realize this, I will be revising this code much, as its my VERY FIRST php project. You will see lots of me.
If you're trying to read an entire file at once, it's often more efficient and a lot easier to simply use file_get_contents().
Likewise, file_put_contents() is often easier than doing an fopen/fwrite/fclose series.
6) Noted. I will be researching this.
Why do you have a double dollar sign on line #18 of your code snippet above? This should be generating error messages, so either you're ignoring them (why?!) or you don't have a very good development environment (e.g. display_errors set to On and error_reporting set to E_ALL).
7) Yes. After posting my code I fiddled with it some more, it displayed that error, and i removed the duplicate dollar sign.
Your code is technically vulnerable to a race condition, but I'd be more worried about the efficiency/consistency of the way you're storing/handling data.
8) Hmm What do you mean by this? Like unauthorized access?
In other words, why not use a database?
Could you please point me to a tutorial or something that shows me how to properly read and write to a database, securely?