Reputation: 53
How can add the content of a $_GET variable inside my include link
<?php $variable = $_GET['variable']; ?>
where my variable is placed here:
<?php
include 'includes/link_(variable placed here).php';
?>
Upvotes: 0
Views: 108
Reputation: 219834
Just use concatenation:
include 'includes/link_'.$variable.'.php';
FYI, this is a security risk. You should sanitize and validate that value before you use it.
Upvotes: 1
Reputation: 308
This might help:
<?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.
?>
Source: include
Upvotes: 0
Reputation: 64526
It can be concatenated like any other string:
include 'includes/link_' .$variable;
However, when using user input in includes, you must validate and verify the data to ensure you don't leave yourself open to a Local File Inclusion vulnerability.
Upvotes: 0
Reputation: 33522
You can simply use it as the string it is:
include 'includes/link_'.$variable;
Be careful with trying to use includes on code that is based on user input. Trouble trouble, boil and bubble!
Upvotes: 0