The Live Team
The Live Team

Reputation: 21

PHP Read file and check if a certain string exists

So far this is what I have, but it doesn't seem to be working...

    <?
    $file = fopen('wiu.dat','r')
    while (wui = fgets($file)){
    if ($wui = 'True') {
      header("Location: index.html");
      die()
    } else {
      echo"<h2>Down for maintenance.</h2>"
    ;}}
    fclose($fh);
    ?>

Any feedback would be greatly appreciated

Upvotes: 1

Views: 125

Answers (1)

Jason
Jason

Reputation: 2743

I fixed the obvious problems. I added a semicolon after your first line and after die(), changed wui to $wui in your while condition, changed $wui = 'True' to $wui == 'True', changed fclose($fh); to fclose($file); and cleaned up your indentation just so it looks nicer. From there, I guess the success of the code depends on what you've got inside wiu.dat.

<?php
  $file = fopen('wiu.dat','r');
  while ($wui = fgets($file)) {
    if ($wui == 'True') {
      header("Location: index.html");
      die();
    } else {
      echo"<h2>Down for maintenance.</h2>";
    }
  }
  fclose($file);
?>

Upvotes: 3

Related Questions