Jump to content
xisto Community
Sign in to follow this  
AlternativeNick

Help With Fopen Script

Recommended Posts

this is what i have so far, i was just wondering if anyone could help me with a problem im having... i really dont know how to say if a variable doesnt exist, because i want it to either a) choose a random quote or :) choose quote X where X is $get_['n']

could anyone help me please? this is what i have so far :S

<?php$num = $GET_['n'];if ($num == NULL) {$num = rand(1,400);$open = fopen("http://stirk.simplemedicalsupply.com/bash.php?q=".$num, "r");$lines = file("http://stirk.simplemedicalsupply.com/bash.php?q=".$num);foreach ($lines as $line_num => $line) {echo $line;}} else {$open = fopen("http://stirk.simplemedicalsupply.com/bash.php?q=".$num, "r");$lines = file("http://stirk.simplemedicalsupply.com/bash.php?q=".$num);foreach ($lines as $line_num => $line) {echo $line;}} ?>

Share this post


Link to post
Share on other sites

I'm presuming the problem is the line:

if ($num == NULL)
as you say you want to check if a variable exists. Try replacing it with this:

if (!isset($num)) {
That basically checks whether anything has given that variable a value, and it's generally considered better and more reliable than using == NULL.

Share this post


Link to post
Share on other sites

It is better to use

$num = $_REQUEST['n'];
rather than using
$num = $_GET['n'];
since it allows all type of forms - GET forms as well as POST forms.


Also check the fopen operation using urls. This make a long time for file open in some times of high traffic. This makes the script improper working. Use local files only on every time for file operations. Note that the time limit for php execution termination is 30 seconds ( in normal case).

Share this post


Link to post
Share on other sites

actually, ive gotten it all to work now...

<?phpif(!$_GET['n']) {$num = rand(1,400);$open = fopen("http://stirk.simplemedicalsupply.com/bash.php?q=".$num, "r");$lines = file("http://stirk.simplemedicalsupply.com/bash.php?q=".$num);foreach ($lines as $line_num => $line) {echo $line;}} else {if ($_GET['n']) {$open = fopen("http://stirk.simplemedicalsupply.com/bash.php?q=".$_GET['n'], "r");$lines = file("http://stirk.simplemedicalsupply.com/bash.php?q=".$_GET['n']);foreach ($lines as $line_num => $line) {echo $line;}} }?>

If youd like to see what it does, go to http://forums.xisto.com/no_longer_exists/ for a random quote from bash.org, or
http://forums.xisto.com/no_longer_exists/?n=X where x is a number to view a specific numbered quote

Share this post


Link to post
Share on other sites

I Would recommend you to use a isset() function.
This checks whether the Variable IS SET or it is not set.

Also you could use the empty() function.
In this function empty() will find return true if the value of the Variable is empty and false if it is not empty.
The things that the empty() function considers empty could be found on the online manual of PHP.NET:
http://in2.php.net/empty

Hope this all helps you out.
I am willing to help if you need some more.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.