dstew32424 2014-09-06 16:01
浏览 57
已采纳

尝试使用fwrite()将包含PHP的文件写入新密码

I have a PHP script that is executed when a user submits a Change Password Form. It runs great and I have had success writing to the file when using the fgets() and fgetc() methods (this required a lot of code). But I never wanted to do it this way. I want to be able to call the $_SESSION["password"] from my pass.php file and replace it with $newpass using the fwrite() method. The current code does not replace at all.

My PHP script.

<?php
$oldpass = $_SESSION["password"] ;
$newpass = $_POST["newpass"] ;
$session =  fopen( "pass.php" , "r+" ) or die( "Could not open file" )  ;

$session ;
$content = file_get_contents( $session ) ;
$content = str_replace( $oldpass , $newpass , $content ) ;
fwrite( $session , $content ) ;
fclose( $session ) ;
?>

My external PHP file pass.php.

<?php
session_start() ;
$_SESSION["username"] = "imauser" ;
$_SESSION["password"] = "imapass" ;
?>
  • 写回答

1条回答 默认 最新

  • duanduo0520 2014-09-06 16:23
    关注

    The error is in file_get_contents($session). file_get_contents expects a filename not a resource.

    PHP manual

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决