简体   繁体   中英

What am I doing wrong? PHP script with nothing visibly wrong

<?php


$file = fopen("configuration.conf","w+");
$settings['LogEnabled'] = "true";
$settings['Pass'] = "pass";
$settings['ShowWarning'] = "true";
fwrite($file,serialize($settings));


$path = "configuration.conf";
$file2 = file_get_contents($path);
$settings2=unserialize($file2);
echo($settings2['LogsEnabled']);

?>

It ought to show "true" when run. Whats wrong?

I tried fread and fopen for $file2, but neither work.

EDIT: It does not throw an error.

The file has permissions 0740

Not sure if it matters, but you have 'LogEnabled' in the serialize section and 'Log s Enabled' in the unserialize section.

Could that 's' be throwing you off?

Flush (and preferably close the file), before reading its contents.

/* Write stuff to $file */
fflush($file);
fclose($file);
/* Read stuff from file */

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM