...

View Full Version : Php help [read contents]



dreampixz
07-29-2012, 05:08 AM
why does this php code doesn't work.
it is the last bit of the code that not works

it just redirect to the first index.html whatever is in that text file,
would be great if somebody could say what i have messed up


<?php
$onoroff = $_GET["state"]; // Declares the request from index.html as a variable
$textfile = "LEDstate.txt"; // Declares the name and location of the .txt file

$fileLocation = "$textfile";
$fh = fopen($fileLocation, 'w ') or die("Something went wrong!"); // Opens up the .txt file for writing and replaces any previous content
$stringToWrite = "$onoroff"; // Write either 1 or 0 depending on request from index.html
fwrite($fh, $stringToWrite); // Writes it to the .txt file
fclose($fh);
$file = file_get_contents("LEDstate.txt");
if(!strpos($file, "1")) {
header("Location: index.html");
}
else {
header("Location: index1.html");
}

?>

byrondallas
07-29-2012, 02:40 PM
This will work:


$file = file_get_contents("LEDstate.txt");
if(!$file == "1") {
header("Location: index.html");
}
else {
header("Location: index1.html");
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum