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! Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/ 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 Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388314 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 Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388315 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. Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388333 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! Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388345 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 Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388350 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."); Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388354 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 Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388361 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? Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388367 Share on other sites More sharing options...
Drags111 Posted November 10, 2007 Author Share Posted November 10, 2007 nvm i see it Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388368 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 Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388370 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? Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388374 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? Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388389 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); ?> Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388546 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... Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388576 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); ?> Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388581 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 Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388585 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? Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388587 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? Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388591 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 Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388595 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); ?> Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388598 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 Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388609 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. Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388611 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. Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388612 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. Link to comment https://forums.phpfreaks.com/topic/76702-solved-editting-a-txt-file-on-my-server/#findComment-388613 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.