Php function is available in another php page
I have a function that I am using in index.php page and I would like to call it from another php page (other.php). How do I make this function available without re-declaring it? I think this is possible with sessions, but I'm not sure how to do it.
The problem is that it works in index.php because it uses some API declaration but not on other.php. I'm not sure how to set up the API in the other.php page, so I need a session of some kind, not a separate file with functions. Any ideas?
EDIT: Maybe this is confusing, so I'll try to clear it up. I have a let say index.php page with a function: get_loggedin_user () ;, It prints the username. It works in index.php because it is part of a CMS with an API and uses that API. The problem is that I would like to use this function (or in the worst case, pass the username) to another page (other.php) accessible from link.php. Now I would like to print the username on other.php. Is it possible? I know I can pass the name using sessions, and I would like to know how to do that, or if possible, how to access this function. Hope this is clear now.
a source to share
You'd better declare your functions in one php file and include it in all php files wherever you need it.
<?php
// require_once will prevent a file being included multiple times
// and so prevents functions from being redeclared again (which would cause errors)
require_once 'yourfilewithfunctions.php';
$result = call_your_function( $with, $parameters );
?>
a source to share
I would guess it get_loggedin_user();
is retrieving information from the session. Print the session and see what variables are set there. Then you can access them from the other.php page.
For example, if your session has a variable of type "logged_in_user_name", you can access it with $_SESSION['logged_in_user_name']
.
a source to share