pardicity3
01-02-2003, 09:02 PM
Hey,
I am very new to php and actually this is my first ever "homemade" script (figures it wouldn't work!). Here is my situation. I have a program that checks whether or not AIM is open on my computer. The program then writes to a file On if AIM is on and Off if it isn't. It then procceeds to upload that file to a specified directory. What I am trying to do, is write a php script that will find out what the file contains and then do something depending on the contents.
So far, I can open the file and make the contents a string without a problem. My probelm comes when I use an if...elseif...else statement to output different pieces of text depending on the contents of my file.
Here is my code:
<?php
$prog_file_i = fopen("prog0.txt", "r");
$prog_file_s = fgets($prog_file_i, 10);
$prog_file = strtolower($prog_file_s);
if ($prog_file == 'on')
print('AIM status: ON | off');
elseif ($prog_file == 'off')
print('AIM status: on | OFF');
else
print('AIM status: unknown');
?>
The problem I am having is that the script is always printing the else statement (AIM status: unknown). I have put in a print($prog_file) statement just to make sure the file reads "on" and it does. I really don't know what is wrong. I assume it has something to do with my if($prog_file == 'on') statement, but I don't know why.
If you need to see the output of the script I have it uploaded to my site:
http://www.mikesadventures.net/trial/dynamic/trial.php
If you go to that link though, you will see this: "on AIM status: unknown". That little "on" in there is from my previously mentioned print($prog_file) statement that I used just to make sure that $prog_file contained "on".
Also, one last note, I have the program make $prog_file lowercase because I just want to be safe and not have the file reading "On" or something like that.
Thanks ahead of time!
I am very new to php and actually this is my first ever "homemade" script (figures it wouldn't work!). Here is my situation. I have a program that checks whether or not AIM is open on my computer. The program then writes to a file On if AIM is on and Off if it isn't. It then procceeds to upload that file to a specified directory. What I am trying to do, is write a php script that will find out what the file contains and then do something depending on the contents.
So far, I can open the file and make the contents a string without a problem. My probelm comes when I use an if...elseif...else statement to output different pieces of text depending on the contents of my file.
Here is my code:
<?php
$prog_file_i = fopen("prog0.txt", "r");
$prog_file_s = fgets($prog_file_i, 10);
$prog_file = strtolower($prog_file_s);
if ($prog_file == 'on')
print('AIM status: ON | off');
elseif ($prog_file == 'off')
print('AIM status: on | OFF');
else
print('AIM status: unknown');
?>
The problem I am having is that the script is always printing the else statement (AIM status: unknown). I have put in a print($prog_file) statement just to make sure the file reads "on" and it does. I really don't know what is wrong. I assume it has something to do with my if($prog_file == 'on') statement, but I don't know why.
If you need to see the output of the script I have it uploaded to my site:
http://www.mikesadventures.net/trial/dynamic/trial.php
If you go to that link though, you will see this: "on AIM status: unknown". That little "on" in there is from my previously mentioned print($prog_file) statement that I used just to make sure that $prog_file contained "on".
Also, one last note, I have the program make $prog_file lowercase because I just want to be safe and not have the file reading "On" or something like that.
Thanks ahead of time!