tags:

views:

62

answers:

5

I have a function that I use on index.php page and I would like to call it from other php page (other.php). How to make this function available without redeclaration? I think it's achievable using sessions, but I am not sure how to do it exactly.

Th problem is that it works in index.php, because it uses some API declaration, but it doesn't on other.php. I am not sure how to setup the API on other.php page, so I will need some sort of session pass rather than seperate file with functions. Any ideas?

EDIT: Maybe it's confusing, so I will try to clarify it. I have a page let's say index.php with a function: get_loggedin_user(); . It prints the user's name. It works in index.php because it is a part of a CMS system with an API and uses this API. The problem is that I would like to use this function on (or in worst case pass the user's name) to other page (other.php) which is accessible by the link form index.php. Now I would like to print user's name on other.php. Is this achievable? I know I can pass the name using sessions and I would like to know how to do this, or if it is possible, how to access this function. Hope it's clear now.

A: 

function can declare in separate page like functions.php, for use that page include in index.php and your redirect page.

Karthik
+1  A: 

not sessions. sessions can store data, not code.
just place your function into file and then include in both scripts

Col. Shrapnel
+7  A: 

You'ld be better of having your functions declared in one php file and include it in all php files where 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 );

?>
fireeyedboy
please see edit.
Vafello
A: 

Hi, the best think to do is to writte yours functions in an another file (ex.: functions.php). And after that, you do a include like "include_once('functions.php')"...

Kevinrob
edited your code to remove error suppress operator
Col. Shrapnel
A: 

I would assume that get_loggedin_user(); is pulling information from a session. Print out the session and see what variables are being set there. You can then access them from your other.php page.

For example, if the session has a variable like 'logged_in_user_name', you can access it using $_SESSION['logged_in_user_name'].

Scott Saunders