Jump to content

Edit PHP file?


Recommended Posts

I'm trying to edit this file in PHP through AutoIt, I just want to change some aspects of the file like the password for example, but i can't do this. It seems far to complicated for my basic knowledge of AutoIt.

Here's an example of the file i'm trying to change:

<?php
    
    $PUBLISHED_FOLDERS = array(
        "1" => array("name" => "Folder A", "path" => "/foo/bar"),
        "2" => array("name" => "Folder B", "path" => "/foo/bay"),
        "3" => array("name" => "Folder C", "path" => "/foo/bat")
    );
    
    $USERS = array(
        "1" => array("name" => "User 1", "password" => "foo", "default_permission" => "rw", "folders" => array(
            "1" => NULL,
            "2" => NULL,
            "3" => NULL
        )),
        "2" => array("name" => "User 2", "password" => "bar", "default_permission" => "ro", "folders" => array(
            "1" => "Custom name for Folder A",
            "2" => NULL
        ))
    );
    
?>

How can i replace the password 'foo' (for ex.) with '123456'?

Can this be done?

Link to comment
Share on other sites

For this file in PHP, you can use _ReplaceStringInFile function

Wow, I didn't knew that one.

But then again so far I had no similar "problem".

Maybe this will happen some day. :unsure:

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

@Hannes

What is interesting when we help others, is to discover different solutions from those that we know ! Posted Image

Hell, yes. I think there are only few times I read a solution form someone else where I can't learn from. I'm especially insterested in how to do things more efficiently. :unsure:

So for example using a single _ReplaceStringInFile instead of having to read the file replacing and writing it again. That's just awesome. :>

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Thanks all for your answers, but if i have two or more users with the same password in that file, if i StringReplace to change that password, wouldn't that change all the identical passwords?

Link to comment
Share on other sites

Thanks all for your answers, but if i have two or more users with the same password in that file, if i StringReplace to change that password, wouldn't that change all the identical passwords?

Right !

So use this

_ReplaceStringInFile ( 'c:\file.php', '"User 1", "password" => "foo"', '"User 1", "password" => "123456"' )

And don't say me that user can have same names ! Posted Image

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Thanks all for your answers, but if i have two or more users with the same password in that file, if i StringReplace to change that password, wouldn't that change all the identical passwords?

... Then you'll need to loop through that file and look for the lines where the user names match and do the replace there.

E.g.

#include <file.au3>

Dim $a_contents

_FileReadToArray("phpfile.php", $a_contents)

For $i = 1 To $a_contents[0]
    If StringInStr($a_contents[$i], "UserThatShouldMatch") Then $a_contents[$i] = StringReplace($a_contents[$i], "foo", "123456")
EndIf

_FileWriteFromArray("phpfile.php", $a_contents, 1)
Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Right !

So use this

_ReplaceStringInFile ( 'c:\file.php', '"User 1", "password" => "foo"', '"User 1", "password" => "123456"' )

And don't say me that user can have same names ! Posted Image

eheheh... No, that won't happen. :unsure:

Thanks man! Now i understand.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...