0

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 :)

3
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by ryan-t
0

Try the following.

Index.php

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

And Function.php

<?php echo $variable; ?>
0

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;
0

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 :)

0

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)?

0

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);
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.