Hi, i wasn't to be able to transfer variable data on to a script that I've include()'d. I've tried passing it through the URL like "include('function.php?username=$session->username');" but it says that it cannot find that file.

So I'm kinda stuck at the moment :)

Try the following.

Index.php

<?php
$variable='this is a test.';
include('function.php');

And Function.php

<?php echo $variable; ?>

You dont have to pass username to included php page.
e.g. test.php

$username = $session->username;
include('function.php');

Once you have $username on test.php, you can use $username in function.php directly.

functions.php

echo "username is ".$username;

So for example, if i call my $session before i call the function. anything in the $session array would be available to function.php.

Thanks for you help so far :)

Also not sure if this works when using the variable in a function(). Which is basicly what function.php is for. Would i need to add the variable into the function foo($variable)?

Also not sure if this works when using the variable in a function(). Which is basicly what function.php is for. Would i need to add the variable into the function foo($variable)?

Yes that is exactly what you need to do. For example:

<?php $variable='test';
include('second.php');
foo($variable);
function foo($test) {
echo $test;
}
foo($variable);

Try all possibilities and post any bug or issue if still exists.

Thanks guys, managed to sort it out. really appreciate the help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.