Jump to content

Archived

This topic is now archived and is closed to further replies.

Cep

Easy way to determine how the variable is obtianed?

Recommended Posts

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,

[code]
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 = ""; }
  }
}
[/code]

Is there a tidier way to do this?

Share this post


Link to post
Share on other sites
You can use "elseif"-

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

Orio.

Share this post


Link to post
Share on other sites

×

Important Information

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.