Existing file editors in PHP? [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Is there any existing php code that will allow me to edit and save files from the browser?
Ex: a text area on the page site.com/edit.php would save to a specified file? I want to be able to edit files on the fly.
I am hosting the site on XAMPP and cant seem to get FTP working so this would be a big use if I need to edit a file and cant get access to the hosting computer.
This is the closest I have found to what I need, however cant seem to get it to work (the goal is to change 'change.php'):
<?php
if ($changefile) {
$slash = stripslashes($_POST['filetest']);
$filetochange = "change.php";
$filetochangeOpen = fopen($filetochange,"w") or die ("Error editing.");
fputs($filetochangeOpen,$slash);
fclose($filetochangeOpen) or die ("Error Closing File!");
}
?>
<form method=post action="">
<textarea rows="40" cols="60" name="filetest">
<?
// Implode CSS
$filetochange = "change.php";
print (implode("",file($filetochange)));
?>
</textarea><br />
<br />
<input type="submit" value="Change File" name="changefile">
</form>

www-data has to have write permission for the files or it won't work. Be careful with this. Either limit access to your own IPs (as you said) or put in a password protected folder with SSL.
<?php
$file = $_POST['file'];
$script = $_POST['script'];
if($file&&$script) {
$fp=fopen($file, "w");
fwrite($fp,$script);
fclose($fp);
}
?>
<form method="post">
<?php
if($file) {
?>
<textarea style="height: 90%; width: 100%;" name="script">
<?php
$fp=fopen($file,"r");
$t="";
while(!feof($fp)) {
$t.=fread($fp,1024);
}
fclose($fp);
print $t;
?>
</textarea>
<input type="hidden" name="file" value="<?=$file;?>">
<?php
}
else
{
?>
Name of file: <input type="text" name="file"><br />
<?php
}
?>
<br />
<input type="submit">
</form>

Related

How to add multiple passwords to this PHP code? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
I don't know PHP and have downloaded this code that works perfectly fine.
I add this code on top of any *.php file and it makes that page, password protected that only opens up if you type the password which in this case is 1234.
Now, I want to add 3 passwords instead of 1. I just don't know where to edit this code.
<?php
session_start();
if(isset($_POST['submit_pass']) && $_POST['pass'])
{
$pass=$_POST['pass'];
if($pass=="1234")
{
$_SESSION['password']=$pass;
}
else
{
$error="Incorrect Pssword";
}
}
if(isset($_POST['page_logout']))
{
unset($_SESSION['password']);
}
?>
<?php
if($_SESSION['password']=="1234")
{
?>
<form method="post" action="" id="logout_form">
<input type="submit" name="page_logout" value="Logout">
</form>
<?php
}
else
{
?>
<form method="post" action="">
<div>Protected Content</div>
<br />
<input type="password" name="pass" placeholder="Type your password">
<input type="submit" name="submit_pass" value="Login">
<br /><br />
<div><?php echo $error;?></div>
</form>
<?php
}
?>
Where should I, add what, to be able to have 3 possible passwords?
For this, you may edit password checking line like this:
<?php
session_start();
if(isset($_POST['submit_pass']) && $_POST['pass'])
{
$pass=$_POST['pass'];
$available_passwords = ['12345','pass123','myOtherPassword'];
if(in_array($pass,$ava_passwords))
{
$_SESSION['password']=$pass;
}
else
{
$error="Incorrect Pssword";
}
}
if(isset($_POST['page_logout']))
{
unset($_SESSION['password']);
}
?>

question about execute PHP file, from other php file on the same folder [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 months ago.
Improve this question
i download 2 php file, one is index. php for input form, and other is insert.php. i have put them on the same folder.
when i click submit it execute insert.php file it work fine and it insert form data into my database. but the question is: how it is called? no code line on the index.php calling the insert.php file.
here is a code of index.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>GFG- Store Data</title>
</head>
<body>
<center>
<h1>Storing Form data in Database</h1>
<form action="insert.php" method="post">
<p>
<label for="firstName">Name:</label>
<input type="text" name="name" id="name">
</p>
<p>
<label for="lastName">Branch:</label>
<input type="text" name="branch" id="branch">
</p>
<p>
<label for="Gender">Roll Number:</label>
<input type="text" name="roll_no" id="roll_no">
</p>
<input type="submit" value="Submit">
</form>
</center>
</body>
</html>
here is the code of insert.php
<!DOCTYPE html>
<html>
<head>
<title>TEST</title>
</head>
<body>
<center>
<?php
$conn = mysqli_connect("localhost", "root", "", "test");
// Check connection
if($conn === false){
die("ERROR: Could not connect. "
. mysqli_connect_error());
}
// Taking all 3 values from the form data(input)
$name = $_REQUEST['name'];
$branch = $_REQUEST['branch'];
$roll_no = $_REQUEST['roll_no'];
// Performing insert query execution
// here our table name is college
$sql = "INSERT INTO student VALUES ('$name','$branch','$roll_no')";
if(mysqli_query($conn, $sql)){
echo "<h3>data stored in a database successfully."
. " Please browse your localhost php my admin"
. " to view the updated data</h3>";
}
else{
echo "ERROR: Hush! Sorry $sql. "
. mysqli_error($conn);
}
// Close connection
mysqli_close($conn);
?>
</center>
</body>
</html>
insert.php is calling after clicking on submit button by "action" attribute which you have used in tag.
<form action="insert.php" method="post">
You can set another path as well as if you want to keep insert.php on any other folder location.

How to control the execution of PHP code [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
with this example I recap my problem:
The first time I execute this php page I want to echo "I have two buttons".When the user click buttons "next" or "next1" I want to echo "I already said I have two buttons" and not "I have to buttons" again.I proved also with hidden input text but it doesn't work. thk for help
<?php
if ($_SESSION['already_said'] == false ){
echo "I have two buttons". date('h:i:s')."<br>";
}
$_SESSION['already_said']=true;
if( isset($_GET["next"]) || isset($_GET["next1"])) {
echo "I already said I have two buttons". date('h:i:s')."<br>";
}
?>
<html>
<body>
<form name="form" method="GET" action="" >
<button type="submit" name="next">
<span class="label">Next</span>
</button>
<button type="submit" name="next1">
<span class="label">Next1</span>
</button>
</form>
</body>
</html>
Of course the important thing is to remember to put the session_start() at the top of any script that uses the session. In fact it is a good idea to put it in all your scripts even if a few dont use the session just to keep the session alive.
<?php
session_start();
$msg = "I have two buttons ". date('h:i:s')."<br>";
if (! isset($_SESSION['already_said']) ){
$_SESSION['already_said'] = true;
}
if( (isset($_GET["next"]) || isset($_GET["next1"]) ) && isset($_SESSION['already_said'])) {
$msg = "I already said " . $msg;
}
?>
<html>
<body>
<div> <?php echo $msg; ?></div>
<form name="form" method="GET" action="" >
<button type="submit" name="next">
<span class="label">Next</span>
</button>
<button type="submit" name="next1">
<span class="label">Next1</span>
</button>
</form>
</body>
</html>

HTML form submit content with PHP to .txt file - blank? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I created a HTML form which should submit the inputted text into a .txt file with PHP, but it only creates a blank line and I don't know what the issue is.
Help is greatly appreciated!
<form class="form-inline validate" name="form1" method="post" action="signup.php" target="_blank" novalidate>
<div class="row no-gutter">
<div class="col-sm-9">
<input type="email" value="" name="mail" class="form-control" placeholder="Subscribe to our newsletter" required>
</div>
<div class="col-sm-3">
<input type="submit" value="SUBSCRIBE" name="Submit">
</div>
</div>
</form>
<?php
$username = $_POST['user'];
//the data
$data = "$email\n";
//open the file and choose the mode
$fh = fopen("users.txt", "a");
fwrite($fh, $data);
//close the file
fclose($fh);
print "User Submitted";
?>
If you want to get mail change your php code to
<?php
if(isset($_POST['Submit'])){
$email = $_POST['mail'];
//the data
$data = "$email\n";
//open the file and choose the mode
$fh = fopen("users.txt", "a+");
fwrite($fh, $data);
//close the file
fclose($fh);
print "User Submitted";
}
?>

php file creation and how to run my php program

I'd like if someone could give me some advice on creating the php file, i know to php language.but where to write it.i have followed some tutorial to run php file in netbeans but its pathethic to download xamp server,apache http server.can u give me the direct of how make configuration and all.i have window7 ultimate and will file i hav to download i don't know. i have netbeans all bundle feature and wamp server.how should i write my php program successfully.plz help me to resolve this.
i m editing the question becoz in comment it is than wordspace given there thatwhy not accepting
thanks its working..
can u tell me why this code doesnot work properly
my php code(or content is this)
<html>
<head>
<title>Binary Search</title>
<style type="text/css">
h1 {color: blue}
</style>
</head>
<body>
<h1 align="center">Computer guess number by using binary search</h1>
<form method="GET">
<?
if (empty($flag_num))
{
$flag_num = -1;
}
if ($flag_num==-1)
{
if (empty($max_num)) $max_num = -1;
if (empty($min_num)) $min_num = -1;
$flag_num = 1;
print <<<Here
<input type="hidden" name="flag_num" value="$flag_num">
<input type="hidden" name="max_num" value="$max_num">
<input type="hidden" name="min_num" value="$min_num">
Input your hidden number: <input type="text" name="hid_num" value="$hid_num"> (1-99)
<br>
<input type="submit" value="Now let's computer guess">
Here;
}
else
{
if ($max_num==-1 && $min_num==-1)
{
$max_num = 100;
$min_num = 0;
$result_num = $hid_num;
}
else
{
if ($comparision == "bigger")
{
$min_num = $guess_num;
}
else if ($comparision == "smaller")
{
$max_num = $guess_num;
}
}
$guess_num = ($max_num + $min_num)/2;
setType($guess_num,"integer");
print "Computer guess <h3> $guess_num </h3>";
if ($guess_num == $result_num)
{
$flag_num = -1;
}
if ($flag_num == -1)
{
print <<<Here
<input type="hidden" name="flag_num" value="$flag_num">
<h1> Congratulation, Computer win </h1>
<input type="submit" value="Next>>>" >
Here;
}
else
{
print <<<Here
<input type="hidden" name="flag_num" value="$flag_num">
<input type="hidden" name="max_num" value="$max_num">
<input type="hidden" name="min_num" value="$min_num">
<input type="hidden" name="guess_num" value="$guess_num">
<input type="hidden" name="result_num" value="$result_num">
<br>
Your intruction: <input type="radio" name="comparision" value="bigger"> Bigger
<input type="radio" name="comparision" value="smaller"> Smaller
<br>
<input type="submit" value="Submit">
Here;
}
}
?>
</form>
</body>
</html>
it doesnot giving the output properly as required
wherever wamp is installed go to the folder "www", put the the php file there
then go to localhost:8080/yourfile.php
that's all there is to it
You could write PHP code in almost anything, and the file will be created as long as you add the .php extension to the new file. I wrote a few simple programs using Notepad and Notepad++ before going onto Eclipse PDT.
To run your file, one out of many ways, you can start up your WAMPserver, browse to http://localhost and drag and drop your file into the browser.
You could also put the .php file inside the www folder (IIRC thats the name of the folder, my memory is a bit hazy) and then browse to http://localhost/name_of_file.php. In either case, if successful, your PHP code should execute on the page.

Categories