English 中文(简体)
使用提取功能生成的固定变量
原标题:isset variables created using extract function
  • 时间:2011-10-05 04:04:22
  •  标签:
  • php
$array = explode( / , $_SERVER[ REQUEST_URI ]);

$count = count($array);

extract($array, EXTR_PREFIX_ALL,  var );

can the variables (created using extract function) be isseted automatically? to avoid "Notice: Undefined variable:" errors when error_reporting(E_ALL); is enabled.

thank you

I tried doing something of this sort, still needed to isset() whenever, the variables are used next in the code (when error_reporting(E_ALL); is enabled).

if(isset($var_0))
{    
$var_0 = filter_var($var_0, FILTER_SANITIZE_STRING);  
}
if(isset($var_1))
{
$var_1 = filter_var($var_1, FILTER_SANITIZE_STRING);
}
if(isset($var_2))
{
$var_2 = filter_var($var_2, FILTER_SANITIZE_STRING);
}
if(isset($var_3))
{
$var_3 = filter_var($var_3, FILTER_SANITIZE_STRING);
}

==========================

或者,如果条件允许,就对一行进行了审判,

$var_0 = isset($var_0) ? filter_var($var_0, FILTER_SANITIZE_STRING) :   ;     
$var_1 = isset($var_1) ? filter_var($var_1, FILTER_SANITIZE_STRING) :   ;
$var_2 = isset($var_2) ? filter_var($var_2, FILTER_SANITIZE_STRING) :   ;
$var_3 = isset($var_3) ? filter_var($var_3, FILTER_SANITIZE_STRING) :   ;

虽然错误被忽略,但产生了一个新问题,即变数(如果情况处理,并非由采掘功能造成的变数正在形成)。

我在网站上张贴了两个路由规则(两个航程)。

$pagename = "not-found.php";

//Different Routing Engine Rules follows

if ((isset($var_1)) && (($var_1 == "") || ($var_1 == "index.php"))) {


     if((isset($var_2)) || (isset($var_3)) || (isset($var_4)) || (isset($var_5)) || (isset($var_6)) || (isset($var_7)))
    {
      $pagename = "not-found.php";

    }
    else
    {

      $pagename = "default-home.php";

    }
}

if (($var_1 == "login")) 
{
//echo "Login Page URL
";      

    if((isset($var_2)) || (isset($var_3)) || (isset($var_4)) || (isset($var_5)) || (isset($var_6)) || (isset($var_7)))
    {
      $pagename = "not-found.php";
    }
    else
    {
      $pagename = "login.php";  
    }
}

include "code/" . $pagename;

感谢您的帮助。

问题回答

如果我能正确理解你的问题,那就没有。 你们仍然有责任知道有哪些变量,并相应地采取行动。 你可以简单地通过<代码>error_ reporting(E_ALL & ~E_NOTICE)将这些通知贴上有关守则的部分。

<><>Edit>/strong>

看看你的最新问题,我认为,如果你能够解释你重新努力实现的目标,那将是有益的。 个人资料见<代码>extract的使用。 a. 作为法典的缩略语,也许有更好的办法:





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签