Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameter while including PHP script

Tags:

include

php

I want to do this, but it gives error :( for better understanding my problem I'm giving an example:

<?php
include 'script.php?text=hiii';
?>

content of the script.php

<?php
echo $_GET['text'];
?>

So, how can i pass an argument while including the script page?

like image 818
Sourav Avatar asked Apr 12 '26 02:04

Sourav


2 Answers

You could set $_GET['text'] before including the file:

$_GET['text'] = 'hiii';
include 'script.php';

But this obviously won’t affect other variables like $_SERVER['REQUEST_URI'], $_SERVER['QUERY_STRING'] etc.

like image 190
Gumbo Avatar answered Apr 13 '26 16:04

Gumbo


After you include any script, the included script will act as it's in the same page.

For yourpage.php?text=hiii, that include('script.php') will automatically print hiii, as content of script.php will be in your included page.

like image 25
Santosh Linkha Avatar answered Apr 13 '26 16:04

Santosh Linkha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!