Editing a PHP File, with another php file, using Fwrite

后端 未结 2 523
攒了一身酷
攒了一身酷 2021-02-02 04:37

My last question wasn\'t explained very well.

What I\'m trying to do here is insert data into a PHP File, Using the fwrite feature on another .php file.

To keep

2条回答
  •  无人及你
    2021-02-02 04:58

    Ok much better alternative use a data file. Ill use json because its easy to use an very easy to parse by human eyes as well:

    // read file
    $data = file_get_contents('data.json');
    $json = json_decode($data, true);
    
    // manipulate data
    $json['users'][] = $_GET['user'];
    
    // write out file
    $dataNew = json_encode($json);
    file_put_contents('data.json', $dataNew);
    

    the reason is, php code is in the staff.php

    Well this isnt something you workaround. You should be writing/reading this kind of information form a data stor - that could be a file or a database... but not an actual script.

提交回复
热议问题