FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
common-parm.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************
3  Copyright (C) 2008-2012 Hewlett-Packard Development Company, L.P.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License version 2.1 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this library; if not, write to the Free Software Foundation, Inc.0
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  ***********************************************************/
18 
25 define("PARM_INTEGER",1);
27 define("PARM_NUMBER",2);
29 define("PARM_STRING",3);
31 define("PARM_TEXT",4);
33 define("PARM_RAW",5);
34 
57 function GetParm($parameterName, $parameterType)
58 {
59  $Var = null;
60  if (array_key_exists($parameterName, $_GET)) {
61  $Var = $_GET[$parameterName];
62  }
63  if (! isset($Var) && isset($_POST) && array_key_exists($parameterName, $_POST)) {
64  $Var = $_POST[$parameterName];
65  }
66  if (! isset($Var) && isset($_SERVER) &&
67  array_key_exists($parameterName, $_SERVER)) {
68  $Var = $_SERVER[$parameterName];
69  }
70  if (! isset($Var) && isset($_SESSION) &&
71  array_key_exists($parameterName, $_SESSION)) {
72  $Var = $_SESSION[$parameterName];
73  }
74  if (! isset($Var) && isset($_COOKIE) &&
75  array_key_exists($parameterName, $_COOKIE)) {
76  $Var = $_COOKIE[$parameterName];
77  }
78  if (! isset($Var)) {
79  return null;
80  }
81  /* Convert $Var to a string */
82  switch ($parameterType) {
83  case PARM_INTEGER:
84  return (intval($Var));
85  case PARM_NUMBER:
86  return (floatval($Var));
87  case PARM_TEXT:
88  return (stripslashes($Var));
89  case PARM_STRING:
90  return (urldecode($Var));
91  case PARM_RAW:
92  return ($Var);
93  }
94  return null;
95 } // GetParm()
96 
100 function Traceback()
101 {
102  return(@$_SERVER['REQUEST_URI']);
103 } // Traceback()
104 
108 function Traceback_uri()
109 {
110  $V = explode('?',@$_SERVER['REQUEST_URI'],2);
111  return($V[0]);
112 } // Traceback_uri()
113 
120 function Traceback_parm($ShowMod=1)
121 {
122  $V = explode('?',@$_SERVER['REQUEST_URI'],2);
123  /* need to check the size to avoid accessing past the array, there are
124  * request URI's that only have a single entry after the explode.
125  */
126  if (count($V) >= 2) {
127  $V = preg_replace("/^mod=/", "", $V[1]);
128  } else if (count($V) == 1) {
129  $V = 'Default';
130  }
131 
132  if (! $ShowMod) {
133  $V = preg_replace("/^[^&]*/", "", $V);
134  }
135 
136  if (is_array($V)) {
137  return $V[0];
138  }
139  return $V;
140 } // Traceback_parm()
141 
147 function Traceback_parm_keep($List)
148 {
149  $Opt="";
150  $Max = count($List);
151  for ($i = 0; $i < $Max; $i ++) {
152  $L = &$List[$i];
153  $Val = GetParm($L, PARM_STRING);
154  if (! empty($Val)) {
155  $Opt .= "&" . "$L=$Val";
156  }
157  }
158  return($Opt);
159 } // Traceback_parm_keep()
160 
164 function Traceback_dir()
165 {
166  $V = explode('?',@$_SERVER['REQUEST_URI'],2);
167  $V = $V[0];
168  $i = strlen($V);
169  while (($i > 0) && ($V[$i - 1] != '/')) {
170  $i --;
171  }
172  $V = substr($V,0,$i);
173  return($V);
174 } // Traceback_uri()
175 
180 {
181  if (! empty(@$_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' &&
182  $_SERVER['HTTPS'] == 'on' || @$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
183  $protoUri = 'https://';
184  } else {
185  $protoUri = 'http://';
186  }
187  $portUri = (@$_SERVER["SERVER_PORT"] == "80") ? "" : (":" . @$_SERVER["SERVER_PORT"]);
188  $V = $protoUri . @$_SERVER['SERVER_NAME'] . $portUri . Traceback_uri();
189  return($V);
190 } // tracebackTotalUri()
const PARM_RAW
Definition: common-parm.php:33
Traceback_uri()
Get the URI without query to this location.
const PARM_TEXT
Definition: common-parm.php:31
Traceback_parm($ShowMod=1)
Get the URI query to this location.
const PARM_NUMBER
Definition: common-parm.php:27
tracebackTotalUri()
Get the total url without query.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:57
const PARM_STRING
Definition: common-parm.php:29
const PARM_INTEGER
Definition: common-parm.php:25
Traceback_dir()
Get the directory of the URI without query.
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
Traceback()
Get the URI + query to this location.