• Welcome to Valhalla Legends Archive.
 

[PHP] Question refering to URL Processing

Started by AC_Drkan, December 02, 2004, 05:08 PM

Previous topic - Next topic

AC_Drkan

Im trying to take a url like this:

www.clan-n2o.com/index.php?view=Console&action=StatsChecker&user=Me


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):

switch ($view) {
case "Console":
switch($action) {
case "StatsChecker":
switch($user) {
case "";  // ?? user has a value? <-- problem here
break;
default:
StatsCheck();
break;
}
break;
                }
}


Ideas:

switch ($view) {
case "Console":
switch($action) {
case "StatsChecker":
switch($user) {
case isset($user);  // would this work?
break;
default:
StatsCheck();
break;
}
break;
                }
}
"The Arguments of Today Result in the Wars of Tomorrow" - Quote By Muah.
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

<kow`> "There are 10 types of people in the world... those who understand binary and those who don't."
<SpaceRain> That's only 2 types of people, kow.
<SpaceRain> STUPID


<[TN]FBMachine> i got kicked out of barnes and noble once for moving all the bibles into the fiction section

God i love Bash.org.

Dyndrilliac

#1
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:

if(isset($user) or $user == "") {
die("Error: No user specified.");
} else {
StatsCheck();
}
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

AC_Drkan

#2
But is there any way to use a switch statement?

like this:

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;


Reason is im writing a complete Clan Script off of 1 file and i wanted to fully parse the url.
"The Arguments of Today Result in the Wars of Tomorrow" - Quote By Muah.
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

<kow`> "There are 10 types of people in the world... those who understand binary and those who don't."
<SpaceRain> That's only 2 types of people, kow.
<SpaceRain> STUPID


<[TN]FBMachine> i got kicked out of barnes and noble once for moving all the bibles into the fiction section

God i love Bash.org.

MyndFyre

Rather than having intensively-loaded switch conditions within other switch conditions, you should subdivide into smaller functions, for instance:


case "Console":
   testConsole($action);
   break;
case "Something":
   testSomething($action);
   break;


// later
function testConsole($action) {
  switch ($action) {
    // blah
  }
}


That makes debugging easier and code maintenance MUCH easier.     
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Black4C6F747573

Quote from: AC_Drkan on December 02, 2004, 05:08 PM
Im trying to take a url like this:

www.clan-n2o.com/index.php?view=Console&action=StatsChecker&user=Me


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):

switch ($view) {
case "Console":
switch($action) {
case "StatsChecker":
switch($user) {
case "";  // ?? user has a value? <-- problem here
break;
default:
StatsCheck();
break;
}
break;
                }
}


Ideas:

switch ($view) {
case "Console":
switch($action) {
case "StatsChecker":
switch($user) {
case isset($user);  // would this work?
break;
default:
StatsCheck();
break;
}
break;
                }
}


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:



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.';
           
           

AC_Drkan

#5
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:

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>");
}


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:

Hello Again there your last visit to this site was on $lastvisit.

"The Arguments of Today Result in the Wars of Tomorrow" - Quote By Muah.
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

<kow`> "There are 10 types of people in the world... those who understand binary and those who don't."
<SpaceRain> That's only 2 types of people, kow.
<SpaceRain> STUPID


<[TN]FBMachine> i got kicked out of barnes and noble once for moving all the bibles into the fiction section

God i love Bash.org.

Banana fanna fo fanna


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.