Author | Message | Time |
---|---|---|
AC_Drkan | Im trying to take a url like this: [code] www.clan-n2o.com/index.php?view=Console&action=StatsChecker&user=Me [/code] using a switch statement i was able to parse the data correctly but then i came to and question: How would i check to see whether user has a value? Here is my code (so far): [code] switch ($view) { case "Console": switch($action) { case "StatsChecker": switch($user) { case ""; // ?? user has a value? <-- problem here break; default: StatsCheck(); break; } break; } } [/code] Ideas: [code] switch ($view) { case "Console": switch($action) { case "StatsChecker": switch($user) { case isset($user); // would this work? break; default: StatsCheck(); break; } break; } } [/code] | December 2, 2004, 11:08 PM |
Dyndrilliac | Your first code snippet should work, I'd use the die() function though in that case though assuming you want the script to stop if $user doesn't have a value. I would use a check like: [code]if(isset($user) or $user == "") { die("Error: No user specified."); } else { StatsCheck(); }[/code] | December 2, 2004, 11:21 PM |
AC_Drkan | But is there any way to use a switch statement? like this: [code] case "Console": switch($action) { case "StatsChecker": switch($user) { case isset($user): switch ($game) { case isset($game): getstats($user, $game); break; default: StatsCheck-Enter(); break; } break; default: StatsCheck-Enter(); break; } break; // Next Case goes here } break; [/code] Reason is im writing a complete Clan Script off of 1 file and i wanted to fully parse the url. | December 3, 2004, 12:06 AM |
Myndfyr | Rather than having intensively-loaded switch conditions within other switch conditions, you should subdivide into smaller functions, for instance: [code] case "Console": testConsole($action); break; case "Something": testSomething($action); break; // later function testConsole($action) { switch ($action) { // blah } } [/code] That makes debugging easier and code maintenance MUCH easier. | December 3, 2004, 2:24 AM |
Black4C6F747573 | [quote author=AC_Drkan link=topic=9753.msg90836#msg90836 date=1102028921] Im trying to take a url like this: [code] www.clan-n2o.com/index.php?view=Console&action=StatsChecker&user=Me [/code] using a switch statement i was able to parse the data correctly but then i came to and question: How would i check to see whether user has a value? Here is my code (so far): [code] switch ($view) { case "Console": switch($action) { case "StatsChecker": switch($user) { case ""; // ?? user has a value? <-- problem here break; default: StatsCheck(); break; } break; } } [/code] Ideas: [code] switch ($view) { case "Console": switch($action) { case "StatsChecker": switch($user) { case isset($user); // would this work? break; default: StatsCheck(); break; } break; } } [/code] [/quote] isset will not accomplish what you want because even if user===''; isset($user) will still return true. isset returns false only if user=== NULL; || unset($user); what you might try to do is this, if you can use if's: [code] switch($_GET['user']) case isset($_GET['user']): if($_GET['user']==='') echo 'You didn\'t enter a username.'; else{ echo $_GET['user'].' was entered as a username.' } default: echo 'Either you are trying to access this page directly, or your login was not correctly parsed. Please attempt to re-loggin. Thankyou.'; [/code] | December 3, 2004, 12:28 PM |
AC_Drkan | Ok thy on that subject. Now i got another: i cannot set a cookie in php, i know the code, and my clan scripts are running fine. but for some odd reason this: [code] if (isset($_COOKIE['visit'])) { $lastvisit = $visit; echo("<p align=\"center\"><FONT FACE=\"Tahoma\" SIZE=\"1\" COLOR=\"#FFFFFF\">Hello Again there your last visit to this site was on $lastvisit.</p>"); } else { setcookie("visit", date( "D M d, Y H:i:s \G\M\T\."), time() + 3600); echo("<p align=\"center\"><FONT FACE=\"Tahoma\" SIZE=\"1\" COLOR=\"#FFFFFF\">Hello and Welcome To This Clan, This is your first visit to thes site today!</p>"); } [/code] does absolutely nothing, I have looked at every php manual that i can think of and it says that this code would be correct but for some weird reason, it will not output: [code] Hello Again there your last visit to this site was on $lastvisit. [/code] | December 3, 2004, 10:18 PM |
St0rm.iD | line 2 $lastvisit = $_COOKIE['visit']; | December 4, 2004, 10:15 PM |
Black4C6F747573 | cookies can not be set after anything has been outputted to the screen. This includes echo commands and even the <html> tag. Be sure to set your cookies at the top of every page. | December 5, 2004, 2:03 AM |