3

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?

0

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

1

You could've done something like this:

<?php
$_GET['text'] = 'what you want to do';
include('script.php');
?>

2 Comments

thnx to both of you, thats really new to me :)
your welcome and welcome to stackoverflow. Be sure to read stackoverflow.com/faq
0

Actually we don't need to add it to $_GET. just create a variable and use it. Example:

script.php
    <title><?php $text; ?></title>
    <!--- other code goes here -->
index.php
    <?php 
    $text = 'Welcome back';
    include 'script.php';
    ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.