Drags111 Posted November 10, 2007 Share Posted November 10, 2007 Ok heres what up: I have a login form with username and password (html of course). When you hit submit, I want the php script i have to make a log of that login. Heres what I got for the html part: <form action="login.php" method="post"> Username: <input type="text" name="usr" /> Password: <input type="password" name="pass" /> <input type="submit" /> </form> I want the php's name to be login.php, and the text file's name is loginlog.txt Thanks! Quote Link to comment Share on other sites More sharing options...
Drags111 Posted November 10, 2007 Author Share Posted November 10, 2007 Also i want the log txt to look like this: ---------------------------------- Username: JohnDoe Password: DoeJohn ---------------------------------- Username: JohnDoe Password: DoeJohn ---------------------------------- Username: JohnDoe Password: DoeJohn ---------------------------------- Username: JohnDoe Password: DoeJohn ---------------------------------- Username: JohnDoe Password: DoeJohn ---------------------------------- Username: JohnDoe Password: DoeJohn and so on Quote Link to comment Share on other sites More sharing options...
farkewie Posted November 10, 2007 Share Posted November 10, 2007 What have you tried? i recommend using MYSQL. http://www.phpfreaks.com/tutorials.php Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 10, 2007 Share Posted November 10, 2007 This is actually a very simple piece of code :-o I'll show you how to use it for appending (check it out online to see how it works). <?php $file = "url_to_text_file.txt"; $data = null;//clear off $data just in case it was cached somehow... if(!is_writable($filename)) {//determine if we can write to the file first, we can't so let's die die("I'm sorry, we encountered an internal error. Please contact the administrator about this problem."); } if(!$file = fopen($file,"a")){//open the file, check to see if we can or cannot die("I'm sorry, the file cannot be opened. Please contact the administrator about this problem."); //next, define what is to be added to the text file //format of //username //password //timestamp of log in (for other purposes) //-------------------- (20 times) $data .= $username."\n"; $data .= $password."\n"; $data .= time()."\n"; $data .= "----------------------------------------"."\n"; if(!fwrite($file,$data)){//we couldn't write to the file die("I'm sorry, we could not write the data to the file. Please contact the administrator about this problem."); } echo "Success. You have written <textarea style='width:100%;height:100px;'>$data</textarea> into the file $filename."; ?> This may look like a lot, but there's a lot of error catching and handling in here, it's better to be safe than sorry. Quote Link to comment Share on other sites More sharing options...
Drags111 Posted November 10, 2007 Author Share Posted November 10, 2007 wow thanks a TON for this krat! Ima test it now! Quote Link to comment Share on other sites More sharing options...
Drags111 Posted November 10, 2007 Author Share Posted November 10, 2007 hmm i get an error when i login: Parse error: syntax error, unexpected $end in /home/zendurl/public_html/d/drags111/loginscript.php on line 30 Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 10, 2007 Share Posted November 10, 2007 if you use @kratsg code you missed } after this line die("I'm sorry, the file cannot be opened. Please contact the administrator about this problem."); Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 10, 2007 Share Posted November 10, 2007 I'm sorry, I missed one character o_o Nobody's perfect xD But Teng's right o_o I saw that myself, then refreshed and saw his post :-o Quote Link to comment Share on other sites More sharing options...
Drags111 Posted November 10, 2007 Author Share Posted November 10, 2007 ok so where do i put it in? Quote Link to comment Share on other sites More sharing options...
Drags111 Posted November 10, 2007 Author Share Posted November 10, 2007 nvm i see it Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 10, 2007 Share Posted November 10, 2007 note: dont forget marking all your thread as solved, if it is Quote Link to comment Share on other sites More sharing options...
Drags111 Posted November 10, 2007 Author Share Posted November 10, 2007 unfortunately, its not. The script runs fine, but even after i changed the perms on the txt file to 777, it still says it can not write to the file. What do I do? Quote Link to comment Share on other sites More sharing options...
Drags111 Posted November 10, 2007 Author Share Posted November 10, 2007 Man ive tried everything... Anyone have suggestions? Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 10, 2007 Share Posted November 10, 2007 Oh, silly me, fwrite returns number of bytes, so I gotta fix it :-P This should work. <?php $file = "url_to_text_file.txt"; $data = null;//clear off $data just in case it was cached somehow... if(!is_writable($filename)) {//determine if we can write to the file first, we can't so let's die die("I'm sorry, we encountered an internal error. Please contact the administrator about this problem."); } if(!$file = fopen($file,"a")){//open the file, check to see if we can or cannot die("I'm sorry, the file cannot be opened. Please contact the administrator about this problem."); } $data .= $username."\n"; $data .= $password."\n"; $data .= time()."\n"; $data .= "----------------------------------------"."\n"; if(fwrite($file,$data) === false){//we couldn't write to the file die("I'm sorry, we could not write the data to the file. Please contact the administrator about this problem."); } echo "Success. You have written <textarea style='width:100%;height:100px;'>$data</textarea> into the file $filename."; fclose($file); ?> Quote Link to comment Share on other sites More sharing options...
Drags111 Posted November 10, 2007 Author Share Posted November 10, 2007 omg i still get the internal error from it, which means it cant write to the file. But thats weird because the permissions on that file are 777... Quote Link to comment Share on other sites More sharing options...
Coreye Posted November 10, 2007 Share Posted November 10, 2007 Shouldn't if(!is_writable($filename)) be if(!is_writable($file))? <?php $file = "file.txt"; $data = null;//clear off $data just in case it was cached somehow... if(!is_writable($file)) {//determine if we can write to the file first, we can't so let's die die("I'm sorry, we encountered an internal error. Please contact the administrator about this problem."); } if(!$file = fopen($file,"a")){//open the file, check to see if we can or cannot die("I'm sorry, the file cannot be opened. Please contact the administrator about this problem."); } $data .= $username."\n"; $data .= $password."\n"; $data .= time()."\n"; $data .= "----------------------------------------"."\n"; if(fwrite($file,$data) === false){//we couldn't write to the file die("I'm sorry, we could not write the data to the file. Please contact the administrator about this problem."); } echo "Success. You have written <textarea style='width:100%;height:100px;'>$data</textarea> into the file $filename."; fclose($file); ?> Quote Link to comment Share on other sites More sharing options...
Drags111 Posted November 10, 2007 Author Share Posted November 10, 2007 nice catch there! Ill try it out Quote Link to comment Share on other sites More sharing options...
Drags111 Posted November 10, 2007 Author Share Posted November 10, 2007 wow its still not working. I think it might be my hosting... anyone know a good free hosting i could use? Quote Link to comment Share on other sites More sharing options...
Coreye Posted November 10, 2007 Share Posted November 10, 2007 Are you sure you made the text file a text document and not a HTML document? Quote Link to comment Share on other sites More sharing options...
Drags111 Posted November 10, 2007 Author Share Posted November 10, 2007 its a text doc. This is getting annoying Quote Link to comment Share on other sites More sharing options...
Coreye Posted November 10, 2007 Share Posted November 10, 2007 What's your site link and the txt file link? See if this works; <?php $file = "test.txt"; $data = null;//clear off $data just in case it was cached somehow... if(!$file = fopen($file,"a")) {//open the file, check to see if we can or cannot die("I'm sorry, the file cannot be opened. Please contact the administrator about this problem."); } $data .= $username."\n"; $data .= $password."\n"; $data .= time()."\n"; $data .= "----------------------------------------"."\n"; if(fwrite($file,$data) === false) {//we couldn't write to the file die("I'm sorry, we could not write the data to the file. Please contact the administrator about this problem."); } echo "Success. You have written <textarea style='width:100%;height:100px;'>$data</textarea> into the file $filename."; fclose($file); ?> Quote Link to comment Share on other sites More sharing options...
Drags111 Posted November 10, 2007 Author Share Posted November 10, 2007 http://gma.freehostia.com/login.html http://gma.freehostia.com/loginscript.php http://gma.freehostia.com/loginlogs.txt Quote Link to comment Share on other sites More sharing options...
Drags111 Posted November 10, 2007 Author Share Posted November 10, 2007 Ok I tested your code, and It almost works. It says that i wrote 34556347 to the file, when in fact i did not even put that in. Then i went to check the http://gma.freehostia.com/loginlogs.txt and nothing was there. But then I went to the file manager and looked at the code and it said it was there. Anyway the point is, it posted the way wrong thing. Quote Link to comment Share on other sites More sharing options...
Drags111 Posted November 10, 2007 Author Share Posted November 10, 2007 alright i ALMOST fixed the problem.. Drags111 test 1194707356 ---------------------------------------- the numbers were the timestamp. but that doesnt look like its uh.... right. lol so anyway. we ALMOST got it down. The other thing is that the text doesnt appear when u go to the link, but it does in the file manager. Quote Link to comment Share on other sites More sharing options...
Coreye Posted November 10, 2007 Share Posted November 10, 2007 When I go to; http://gma.freehostia.com/loginlogs.txt, I see the information you entered. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.