thenewperson Posted December 7, 2009 Share Posted December 7, 2009 Hey, i am trying to make upload page and have upload.php and upload-file.php. The upload-file.php contains the testing and moving of the file to the folder. This all works until i put all the testing into a function. I tryed echoing out the username and it comes up blank. When i take it out of the function and echo it, it echos the username out correctly. I am using iframes for the upload.php page and the upload-file.php code with the problem in upload-file.php function uploadtesting(){ $user = $session->username; } The code above works perfectly fine when its not in a function Link to comment https://forums.phpfreaks.com/topic/184225-php-function-problem/ Share on other sites More sharing options...
Brandon_R Posted December 7, 2009 Share Posted December 7, 2009 You need to either pass along the $session variable as an argument in the function or globalize it. Passing it on as an argument function uploadtesting($session) { $user = $session->username; } Globalizing it function uploadtesting() { global $session; $user = $session->username; } For the variablie to be globalized you have to set it before the function is called same goes for passing it on as an argument. Link to comment https://forums.phpfreaks.com/topic/184225-php-function-problem/#findComment-972615 Share on other sites More sharing options...
thenewperson Posted December 7, 2009 Author Share Posted December 7, 2009 Thank you Link to comment https://forums.phpfreaks.com/topic/184225-php-function-problem/#findComment-972618 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.