Hello,
My registar globals are off, and I seem to be in a bit of a constrained environment (which I will give details of below)
I have created a textbox that reads a file. The user can edit the contents of the textbox and if he wants to save he can click the submit button.
All the file permissions and everything are okay, the file opens and reads fine. and no doubt it would write fine. The problem is just getting the submit button to work. Here is my code (and I am using #!/usr/local/bin/php):
elseif ($command == "edit")
{
$datafile=$location."/".$target;
echo "<b>PATH:</b> $datafile";
echo "<br><br>";
echo "<center>";
echo "<form action=\"$refresh?command=edited&location=".$datafile."&target=acquired&datafile=$datafile&original=$original&modified=$modified\" method=\"post\">";
echo "<textarea name=\"editbox\" cols=\"85\" rows=\"30\">";
if (file_exists($datafile))
{
$original = fopen($datafile,"r+");
$modified = fpassthru($original);
}
else
echo "ERROR: The file does not exist, or you do not have permission to edit it.";
echo "</textarea>";
echo "<br><br>";
echo "<input type=\"Submit\" value=\"Save Changes\">";
echo "</center>";
echo "<br><br><a href=\"$refresh?\">Click Here to Return</a>";
}
elseif ($command == "edited")
{
$editbox = $_POST['editbox'];
$datafile = $_GET['datafile'];
$original = $_GET['original'];
$modified = $_GET['modified'];
echo "$modified <br> $editbox <br> $datafile <br> $original <br>this is a test..<br>"; // they are empty
if ($target == "acquired")
{
$original = fopen("$datafile","w+");
$modified = stripSlashes($editbox);
fwrite($original,$modified);
fclose($original);
#unset($modify);
echo "<b>Your changes have been saved.</b>";
}
}
So I put all the variables into "action" but Im not too sure if this is correct. I actually dont know the difference between POST and GET.. which is something I should probably go lookup.
I have been able to extract the ?something=this&more=blah part using:
$arguments = getenv('QUERY_STRING');
But I dont know if that applies to variables or wha. Also to note, the $refresh variable is:
$refresh = getenv('SCRIPT_NAME');
I seem to have to use these special calls. I emailed the guy and this is what he said:
if you need the environmental variables for passing, you can type them like:
USERNAME=bob ./index.html
then you'd use getenv('USERNAME') to get the bob value from within the script.
the following tokens are supported:
DOCUMENT_ROOT
LANGUAGE
USERNAME
USER
HOME
SSL
SESSION_KEY
SESSION_ID
HTTP_COOKIE
HTTP_HOST
SERVER_NAME
REMOTE_ADDR
SERVER_SOFTWARE
SERVER_ADDR
SERVER_PORT
REQUEST_METHOD
REDIRECT_STATUS=CGI
QUERY_STRING
REQUEST_URI
POST
SCRIPT_NAME
So intead of using $PHP_SELF, (which php probably isn't loading for you because php is being run via the shell method not apache php module), you'd probably want to look at getenv('SCRIPT_NAME') instead (some parsing may be required, in combination with getenv('DOCUMENT_ROOT'))
Also, if you are using "GET" variables, you'd have to get them from the getenv('QUERY_STRING') function.
Thank you,
John
The answer is probably in there but I am too unintelligent to figure it out heh. This is the first PHP thing I have ever made, and what I am making is not simple stuff so I've just dived right in without any knowledge.
Your help is greatly appreciated. If you need more information I will gladly provide it.
Thanks!
-Ji