AlternativeNick 0 Report post Posted August 9, 2006 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
rvalkass 5 Report post Posted August 9, 2006 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
ivenms 0 Report post Posted August 9, 2006 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
AlternativeNick 0 Report post Posted August 9, 2006 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, orhttp://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
electron 0 Report post Posted August 18, 2006 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/emptyHope 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