No you cannot send arguments to a local included script.
I see no reason to do so though, if you need dynamic input provided that value into the superglobal before including it in. Alternatively, you can remotely access it using an http wrapper by providing the http://site.com/script.php instead, but this will parse it as its served. You can provide a querystring with this, but you can only capture the results, not deal directly with any developed variables. That will also only work if you have allow_url_include available.

angst

05-24-2011, 06:53 PM

Hey guys, I'm a PHP beginner and was wondering if it is possible to send variables with includes?

For example, if I wanted to do an include from my faq.php page, is it possible to do something like this:

<?php include 'includes/global_footer.php', 'FAQ'; ?>

and from my about.php page:

<?php include 'includes/global_footer.php', 'About'; ?>

Where global_footer.php contains:

<?php

// Using pseudo PHP code

if page == FAQ
<div>This is my footer for the FAQ page</div>

if page == About
<div>This is my footer for the About page</div>

else
<div>This is my footer for all the other pages</div>

?>

How would I write this using PHP code?

no this is not possible. but you could include the page/section name in the include like.

SomeInclude.php:

$PageTitle = "About";

then in your script, simply call the variable after the include, like;

include "SomeInclude.php";
echo $PageTitle;

tangoforce

05-24-2011, 07:30 PM

You might like to see my answer to a similar question here (http://www.codingforums.com/showpost.php?p=1093720&postcount=2).

JAG

05-24-2011, 11:05 PM

I am learning about php myself. I'm not sure if what you pose is possible, but I do something similar with my header div like so :

right after the <body> tag I do my include:
<?php include 'inc/header.php' ?>