320 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

I’m trying to write something to an existing php file using FILE _APPEND.

I want to add the code below to “myString”, The full code. If I place that in between the quotes I get an error. It seems like it doesn’t like the $ symbol. What can I do? I’m not a php expert :)

$useradmin = array('login' => 'admin');    //// add this to myString

$file = "settings.php";
$myString = " ";

file_put_contents($file, $myString, FILE_APPEND);
$getData = file_get_contents($file);
echo $getData;

Thanks!
Timothy

320 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

OK, disregard my last message. I’m now gonna use str_replace.

I got it working, but I need one last thing! I have a simple HTML form with a field name=”albumpass”

How do I add a .$_POST to the second str_replace so it submits what the user places inside that field.

Here is my code:
$fname = "settings.php";
$fhandle = fopen($fname,"r");
$content = fread($fhandle,filesize($fname));

$content = str_replace("defaultpass", "WHAT_EVER_USER_TYPED", $content);

$fhandle = fopen($fname,"w");
fwrite($fhandle,$content);
fclose($fhandle);

Thanks!

320 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

Got it!

$_POST['albumpass'];
$fname = "settings.php";
$fhandle = fopen($fname,"r");
$content = fread($fhandle,filesize($fname));

$content = str_replace("defaultpass", "$albumpass", $content);

$fhandle = fopen($fname,"w");
fwrite($fhandle,$content);
fclose($fhandle);
639 posts
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 2 years
+1 more
Crakken says

Looks like creating a thread about it helped you, you should post here more often :sarcasm:

320 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

Looks like creating a thread about it helped you, you should post here more often :sarcasm:

haha you know what? This crap always happens to me.

I always search for my problems before posting on threads, then after post a thread I figure out my problem. I don’t get it :P

639 posts
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 2 years
+1 more
Crakken says


Looks like creating a thread about it helped you, you should post here more often :sarcasm:

haha you know what? This crap always happens to me.

I always search for my problems before posting on threads, then after post a thread I figure out my problem, I don’t get it :P

Stuffs happen.

by
by
by
by
by
by