Jump to content


Photo

Easy way to determine how the variable is obtianed?


  • Please log in to reply
1 reply to this topic

#1 Cep

Cep
  • Members
  • PipPipPip
  • Advanced Member
  • 539 posts
  • LocationOn a boat in the middle of nowhere

Posted 03 August 2006 - 10:12 AM

Hello,

I am setting up a system were I want to obtain the variable $action value from either a session, get or post action.

At the moment I use a very long if statement like this,

if (isset($_POST['action'])) { 
$action = $_POST['action']; 
} else { 
  if (isset($_GET['action'])) { 
  $action = $_GET['action']; 
  } else { 
    if (isset($_SESSION['action'])) { 
    $action = $_SESSION['action']; 
    } else { $action = ""; } 
  }
}

Is there a tidier way to do this?
Thanks Cep

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 03 August 2006 - 10:42 AM

You can use "elseif"-

<?php
if (isset($_POST['action'])) { 
$action = $_POST['action'];
} elseif(isset($_GET['action'])) {
$action = $_GET['action'];
} elseif(isset($_SESSION['action'])) {
$action = $_SESSION['action'];
else{
$action="";
}
?>

Orio.
Think you're smarty?

(Gone until 20 to November)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users