在include链接中添加$ _GET变量

时间:2014-05-10 13:21:39

标签: php get

如何在我的包含链接

中添加$ _GET变量的内容
<?php $variable = $_GET['variable']; ?>

我的变量放在这里:

<?php
    include 'includes/link_(variable placed here).php';

?>

4 个答案:

答案 0 :(得分:1)

只需使用concatenation

include 'includes/link_'.$variable.'.php';

仅供参考,这是security risk。在使用之前,您应该清理并验证该值。

答案 1 :(得分:0)

您可以简单地将其用作字符串:

include 'includes/link_'.$variable;

小心尝试在基于用户输入的代码上使用包含。麻烦,煮沸和泡沫!

答案 2 :(得分:0)

它可以像任何其他字符串一样连接:

include 'includes/link_' .$variable;

但是,在包含中使用用户输入时,您必须验证并验证数据,以确保您不会对Local File Inclusion vulnerability开放。

答案 3 :(得分:0)

这可能会有所帮助:

<?php

/* This example assumes that www.example.com is configured to parse .php
* files and not .txt files. Also, 'Works' here means that the variables
* $foo and $bar are available within the included file. */

// Won't work; file.txt wasn't handled by www.example.com as PHP
include 'http://www.example.com/file.txt?foo=1&bar=2';

// Won't work; looks for a file named 'file.php?foo=1&bar=2' on the
// local filesystem.
include 'file.php?foo=1&bar=2';

// Works.
include 'http://www.example.com/file.php?foo=1&bar=2';

$foo = 1;
$bar = 2;
include 'file.txt';  // Works.
include 'file.php';  // Works.

?>

来源:include