I have a page that called admin.php that has some cods and buttons. my problem is one of the buttons apply an action code that is originally HTML code but i converted it to php and the code is like this:
echo "<form action=\"write.php\" method=\"post\">\n";
echo " <p>your MoD name: <input type=\"text\" name=\"mdname\" /></p>\n";
echo " <p><input type=\"submit\" /></p>\n";
echo "</form>\n";
this code calls the write.php and write.php code is this:
<?php
header ('Location: admin.php ');
$myFile = "methods\actmod.txt";
unlink($myFile);
$handle = fopen("methods\actmod.txt", "a");
foreach($_POST as $variable => $value) {
fwrite($handle, $variable);
fwrite($handle, "=");
fwrite($handle, $value);
fwrite($handle, "\r\n");
}
fwrite($handle, "\r\n");
fclose($handle);
exit;
?>
this code writes some data to txt file that called actmod.txt and returns to the admin page. i wanted to ask is there any way that i can merge write.php to the main admin.php page so when i hit the submit button in the admin page it won use any external file and runs the commands directly from admin page and i wont have any external files behind the admin page?
i have seen lots of pages that has address like this “http://site.com/admin.php?act=write
i hope every body understand what i mean. i am new to php and i searched a lot and i appreciate to anybody’s help.
thank you
In your admin.php
There may be better ways to identify the request being POST or GET, I am just trying to give you a hint and rest is yours. 🙂