Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Php help [read contents]

    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 Code:
    <?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");
      }
     
    ?>

  • #2
    New Coder
    Join Date
    Jul 2011
    Location
    USA
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post
    This will work:

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

    else { 
        
    header("Location: index1.html"); 
      } 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •