Jump to content


Photo

edit config.php


  • Please log in to reply
17 replies to this topic

#1 Ben Phelps

Ben Phelps
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 16 September 2006 - 10:24 PM

I am wondering how i can open a files (config.php) and change some values via a text box then save.

Example

config.php
<?php

$site_url= "http://127.0.0.1/";

?>

I want to open config.php and change http://127.0.0.1/ to what ever is imputed in the text box.

It will be an install script when its finished


#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 16 September 2006 - 10:44 PM

using fopen()
fwrite()
fclose()
functions

Tell me the problem, I will try tell you the solution

#3 Ben Phelps

Ben Phelps
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 16 September 2006 - 11:16 PM

i don't have any idea how i could do that

#4 makeshift_theory

makeshift_theory
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 16 September 2006 - 11:51 PM

well you could make two php pages like so:

index.php
.....
<body>
<form action="config.php" method="post">
Change Ip to: <input type="text" name="ip">
<input type="submit" name="submit" value="Submit New Ip">
</form>
....
</body>




config.php

<?
if(isset($_POST['submit'])) {
$ipfield = $_POST['ip'];
echo "Current Ip is:" . $ipfield . ".";
}
?>



<b>Emacs</b> it's great for the body.
<br><br>
<b>Trust the TechnoLust</b>

<b><u>Have a question check here:</u></b>
PHP Manual: http://www.php.net

#5 Ben Phelps

Ben Phelps
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 17 September 2006 - 12:02 AM

that is close but i want it to physically edit the file.

so before edit
<?php

$site_url= "http://127.0.0.1/";

?>

after edit

<?php

$site_url= "http://192.168.0.100/";

?>

it is a config file for a script I'm working on

#6 makeshift_theory

makeshift_theory
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 17 September 2006 - 12:39 AM

That script would physically edit the file, it takes the ip from a input box and changes the variable on the config page.  I may not be be completely understanding of what you need but I think from what you just posted it should work for your needs.
<b>Emacs</b> it's great for the body.
<br><br>
<b>Trust the TechnoLust</b>

<b><u>Have a question check here:</u></b>
PHP Manual: http://www.php.net

#7 Ben Phelps

Ben Phelps
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 17 September 2006 - 12:55 AM

i need it to open the file change http://127.0.0.1/ to what ever the user inputs and save the file for later use, not just change the var. when the script is being used

#8 makeshift_theory

makeshift_theory
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 17 September 2006 - 01:01 AM

with that said
fopen('config.php');
fwrite($ipaddress);
fclose();



<b>Emacs</b> it's great for the body.
<br><br>
<b>Trust the TechnoLust</b>

<b><u>Have a question check here:</u></b>
PHP Manual: http://www.php.net

#9 Ben Phelps

Ben Phelps
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 17 September 2006 - 01:29 AM

what do i do with that ??? I'm sorry i don't understand php that well

#10 makeshift_theory

makeshift_theory
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 17 September 2006 - 02:50 AM

use php.net as a reference for function usage.  fopen, fwrite, and fclose open files write text ot files and close an active file.
<b>Emacs</b> it's great for the body.
<br><br>
<b>Trust the TechnoLust</b>

<b><u>Have a question check here:</u></b>
PHP Manual: http://www.php.net

#11 Ben Phelps

Ben Phelps
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 17 September 2006 - 03:30 AM

i have a script that writes the ip to the config.php but it writes to the end of the document.  I need it to write in a certain place.

<?php

$script_url = "it needs to write here" ;

?>not here

Here are the scripts i use now.

get.php

<html>
<head>
<title></title>
</head
<body>
<form action="write.php" method="post">
  <p align="center"><strong>Script Installer </strong><br>
    Where is the script at :<br>
    <input type="text" name="ipfield">
    <br>
    <input type="submit" name="submit" value="Install">
    <br>
    Ex. <strong>http://www.thepchs.com/script/</strong></p>
</form>
</body>
<html>

write.php

<?php
$filename = 'config.php';
$somecontent = "$ipfield";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

   // In our example we're opening $filename in append mode.
   // The file pointer is at the bottom of the file hence
   // that's where $somecontent will go when we fwrite() it.
   if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
   }

   // Write $somecontent to our opened file.
   if (fwrite($handle, $somecontent === TRUE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
  
   echo "Success, wrote $somecontent to file $filename";
  
   fclose($handle);

} else {
   echo "The file $filename is not writable";
}
?>

config.php

<?php

script_url = "";

?>


#12 GeorgeMoney

GeorgeMoney
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 17 September 2006 - 04:52 AM

You could use this script (untested).
<?php
if(isset($_POST['newip'])) {
$newip = $_POST['newip'];
$oldtext = file_get_contents('config.php');
$newtext = preg_replace('/http:\/\/(.*)\//', "http://".$newip."/", $oldtext);
$fp = fopen("config.php", "w");
fwrite($fp, $newtext);
fclose($fp);
} else {
?>
<form method="post" action="<?php echo $_SERVER['SCRIPT_URI'] ?>">
IP: <input type="text" name="newip" /><br>
<input type="submit" value="submit" />
</form>
<?php } ?>

--GeorgeMoney

#13 Ben Phelps

Ben Phelps
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 17 September 2006 - 05:15 AM

THANK YOU VERY MUCH  ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D
It works  ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D

Now is there a way i could do that like 3 more times editing something different every time?  if not thats ok

#14 Ben Phelps

Ben Phelps
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 17 September 2006 - 02:51 PM

its ok i figured it out, and once again thank you ;D ;D ;D ;D ;D

#15 Ben Phelps

Ben Phelps
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 17 September 2006 - 03:34 PM

how can i get it to show a different page after i click submit.  like a conformation page.

#16 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 September 2006 - 03:42 PM

update.php
<?php

if(isset($_POST['newip'])) {
$newip = $_POST['newip'];
$oldtext = file_get_contents('config.php');
$newtext = preg_replace('/http:\/\/(.*)\//', "http://".$newip."/", $oldtext);
$fp = fopen("config.php", "w");
fwrite($fp, $newtext);
fclose($fp);
header("location: thankyou.php");
}
?>

form.php

<html>
<body>
<form method="post" action="update.php">
IP: <input type="text" name="newip" /><br>
<input type="submit" value="submit" />
</form>
</body>
</html>

thankyou.php

<html>
<body>
thank you
</body>
</html>



or easer
<?php
if(isset($_POST['newip'])) {
$newip = $_POST['newip'];
$oldtext = file_get_contents('config.php');
$newtext = preg_replace('/http:\/\/(.*)\//', "http://".$newip."/", $oldtext);
$fp = fopen("config.php", "w");
fwrite($fp, $newtext);
fclose($fp);
echo "thank you";
exit;
} else {
?>
<form method="post" action="<?php echo $_SERVER['SCRIPT_URI'] ?>">
IP: <input type="text" name="newip" /><br>
<input type="submit" value="submit" />
</form>
<?php } ?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#17 GeorgeMoney

GeorgeMoney
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 17 September 2006 - 04:58 PM

Or if you want them to press a 'confirm' button:
<?php
if(isset($_POST['newip'])) {
  if(isset($_POST['confirm'])) {
    $newip = $_POST['newip'];
    $oldtext = file_get_contents('config.php');
    $newtext = preg_replace('/http:\/\/(.*)\//', "http://".$newip."/", $oldtext);
    $fp = fopen("config.php", "w");
    fwrite($fp, $newtext);
    fclose($fp);
  } else {
    echo "Are you sure about that? <form method='post' action='$_SERVER[SCRIPT_URI]'><input type='hidden' name='newip' value='$_POST[newip]' /><input type='submit' name='confirm' value='confirm' /></form>";
  }
} else {
?>
<form method="post" action="<?php echo $_SERVER['SCRIPT_URI'] ?>">
IP: <input type="text" name="newip" /><br>
<input type="submit" value="submit" />
</form>
<?php } ?>

--GeorgeMoney

#18 Ben Phelps

Ben Phelps
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 17 September 2006 - 06:09 PM

WOW!!!  ;D ;D

Thanks for all the help.  It works perfect now.  ;D ;D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users