CG_dude Posted February 7, 2009 Share Posted February 7, 2009 Hi all, Thanks in advance for any solutions; I have a code that pops up a password box "onclick" and I have the onclick set on the Submit button in a form. It is doing what I am expecting it to do, however, you put in the wrong password or even hit cancel and what ever you typed in the text field still gets submitted. I know this is using java script, and I don't care if it's not secure, it's internal, and I doubt anyone would enter in a comment who isn't supose to, however, I would prefer the password protect once the submit button was clicked. I'm thinking it's IF and ELSE statements or where I have the code, but I'm not the best with IF and ELSE, so any suggestions would be great. Below if my entire code, <?php $pafilename="textfile.txt"; //sets file to edit $readfh = fopen($pafilename, "r"); //File handle for $filename $contents = fread($readfh, filesize($pafilename)); //Reads file, through handle $readfh. ?> <HTML> <BODY BGCOLOR='white'" TEXT=BLACK LINK=BLUE VLINK=PURPLE ALINK=RED > <META HTTP-EQUIV="REFRESH" CONTENT="60"> <HEAD> <TITLE>TESTing PHP site</TITLE> </HEAD> <BODY> <STYLE TYPE="text/css"> <!-- H1 { color:303065; font-size:16pt; font-style:italic; } --> </STYLE> <H1> <center> Report Site</H1> <?php echo shell_exec('date +%A,\ %B\ %e,\ %Y\ %I:%M\ %p\ US\ Pacific\ Time'); ?> <TABLE BORDER=2 CELLSPACING=6 BORDERCOLOR=#303065> <TR> <TH>Some Name</TH> <TH>Some Name Name</TH> <TH>Some Name</TH> <TH>Mon.-Thur.</TH> <TH>Weekend </TH> <TH>Comments</TH></TR> <TR> <TD>Transaction </TD> <TD><LI>something</A> </TD> <TD> <?php echo shell_exec('cat textfile.txt'); ?> </TD> <TD><center>8:45pm</TD> <TD><center>10:45pm</TD> <TD> <?php if(isset($_POST['submit'])) { //if submit was pressed $writefh = fopen($pafilename, "w+"); //File handle for $filename if(get_magic_quotes_gpc()){ $newcontents=stripslashes($_POST['editcontents']); } //strips unneeded backspaces by magicquotes else{ $newcontents = $_POST['editcontents']; } //NEXT 3 LINES ARE THE PROBLEM SPOT: fwrite($writefh, $newcontents, strlen($newcontents)); //Saves changes rewind($readfh); //resets cursor in file $contents = fread($readfh, filesize($pafilename)); //Updates $contents fclose($writefh); } ?> <form method="post" action="<? echo($PHP_SELF); ?>"> <textarea name="editcontents" style="width:200px; height:45px;"><? echo shell_exec('cat textfile.txt');?></textarea> <br /> <input onclick="var password = prompt('Enter Password',''); if (password == 'ADMIN') alert('Password Correct! Click OK to enter!');" type="submit" name="submit" value="Comment"/> <?php fclose($readfh); ?> </form> </TD> </TR> </TABLE> <H3> <center>Testing PHP Pahe</H3> </BODY> </HTML> Thanks for any help ??? ??? Link to comment https://forums.phpfreaks.com/topic/144167-help-with-password-prompt-in-a-form/ Share on other sites More sharing options...
Lodius2000 Posted February 7, 2009 Share Posted February 7, 2009 please stare using code tags... its the '#' button between your title and post fields reposted <?php $pafilename="textfile.txt"; //sets file to edit $readfh = fopen($pafilename, "r"); //File handle for $filename $contents = fread($readfh, filesize($pafilename)); //Reads file, through handle $readfh. ?> <HTML> <BODY BGCOLOR='white'" TEXT=BLACK LINK=BLUE VLINK=PURPLE ALINK=RED > <META HTTP-EQUIV="REFRESH" CONTENT="60"> <HEAD> <TITLE>TESTing PHP site</TITLE> </HEAD> <BODY> <STYLE TYPE="text/css"> <!-- H1 { color:303065; font-size:16pt; font-style:italic; } --> </STYLE> <H1> <center> Report Site</H1> <?php echo shell_exec('date +%A,\ %B\ %e,\ %Y\ %I:%M\ %p\ US\ Pacific\ Time'); ?> <TABLE BORDER=2 CELLSPACING=6 BORDERCOLOR=#303065> <TR> <TH>Some Name</TH> <TH>Some Name Name</TH> <TH>Some Name</TH> <TH>Mon.-Thur.</TH> <TH>Weekend </TH> <TH>Comments</TH></TR> <TR> <TD>Transaction </TD> <TD><LI>something</A> </TD> <TD> <?php echo shell_exec('cat textfile.txt'); ?> </TD> <TD><center>8:45pm</TD> <TD><center>10:45pm</TD> <TD> <?php if(isset($_POST['submit'])) { //if submit was pressed $writefh = fopen($pafilename, "w+"); //File handle for $filename if(get_magic_quotes_gpc()){ $newcontents=stripslashes($_POST['editcontents']); } //strips unneeded backspaces by magicquotes else{ $newcontents = $_POST['editcontents']; } //NEXT 3 LINES ARE THE PROBLEM SPOT: fwrite($writefh, $newcontents, strlen($newcontents)); //Saves changes rewind($readfh); //resets cursor in file $contents = fread($readfh, filesize($pafilename)); //Updates $contents fclose($writefh); } ?> <form method="post" action="<? echo($PHP_SELF); ?>"> <textarea name="editcontents" style="width:200px; height:45px;"><? echo shell_exec('cat textfile.txt');?></textarea> <br /> <input onclick="var password = prompt('Enter Password',''); if (password == 'ADMIN') alert('Password Correct! Click OK to enter!');" type="submit" name="submit" value="Comment"/> <?php fclose($readfh); ?> </form> </TD> </TR> </TABLE> <H3> <center>Testing PHP Pahe</H3> </BODY> </HTML> also, dont capitalize your html tags, its not w3c compliant and isnt good practice anymore Link to comment https://forums.phpfreaks.com/topic/144167-help-with-password-prompt-in-a-form/#findComment-756526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.