Cyclone
Cyclone

Reputation: 18295

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

Upvotes: 1

Views: 78

Answers (2)

Eric
Eric

Reputation: 767

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

Could that 's' be throwing you off?

Upvotes: 4

gnud
gnud

Reputation: 78518

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

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

Upvotes: 3

Related Questions