adam291086 Posted September 17, 2008 Share Posted September 17, 2008 i have a function that stores all my ftp username and passwords like <?php function getSettings() { // ftp variables $settings['ftpServer'] = 'la'; $settings['ftpUsername'] = 'la'; $settings['ftpPassword'] = 'dream on'; return $settings; } ?> i want to be able to get these details within another script i have tried include('http://www.rubberduckiee.co.uk/code/ftp_details.php'); $settings = getSettings(); $ftpServer = $settings['ftpServer']; $ftpUser = $settings['ftpUsername']; $ftpPass = $settings['ftpPassword']; $c = @ftp_connect($ftpServer); $l = @ftp_login($c, $ftpUser, $ftpPass); if(!$c) die("A connection to $ftpServer couldn't be established"); else if(!$l) die("Your login credentials were rejected"); else return $c; but all i get is the error message saying undefined function getsettings() on line 18 Link to comment https://forums.phpfreaks.com/topic/124646-solved-function-help/ Share on other sites More sharing options...
uniflare Posted September 17, 2008 Share Posted September 17, 2008 Do not use http urls in include functions, php includes must be local to the server to be parsed. If that does not work:Have you tried a snippet test? Make a file test_inc.php and put JUST the getsettings function in it, then make a test.php and only put the include and function call and see if it errors. I believe you have overlooked a scope change or something, we may need more code as this should work flawlessly. Link to comment https://forums.phpfreaks.com/topic/124646-solved-function-help/#findComment-643749 Share on other sites More sharing options...
adam291086 Posted September 17, 2008 Author Share Posted September 17, 2008 i have just done this to the function i am calling upon <?php error_reporting(E_ALL); function account() { // ftp variables $settings['ftpServer'] = 'la'; $settings['ftpUsername'] = 'sadfs'; $settings['ftpPassword'] = 'Cdsfdsffsdfsdfsdf'; return $settings; } $setting = account(); print_r($setting); ?> and when i run the script the array prints out. But when include i get undefined. Link to comment https://forums.phpfreaks.com/topic/124646-solved-function-help/#findComment-643763 Share on other sites More sharing options...
Prismatic Posted September 17, 2008 Share Posted September 17, 2008 i have just done this to the function i am calling upon <?php error_reporting(E_ALL); function account() { // ftp variables $settings['ftpServer'] = 'la'; $settings['ftpUsername'] = 'sadfs'; $settings['ftpPassword'] = 'Cdsfdsffsdfsdfsdf'; return $settings; } $setting = account(); print_r($setting); ?> and when i run the script the array prints out. But when include i get undefined. You're calling getSettings() the function is account() Link to comment https://forums.phpfreaks.com/topic/124646-solved-function-help/#findComment-643772 Share on other sites More sharing options...
adam291086 Posted September 17, 2008 Author Share Posted September 17, 2008 yeah i have changed the name within the script i include ftp_details Link to comment https://forums.phpfreaks.com/topic/124646-solved-function-help/#findComment-643780 Share on other sites More sharing options...
adam291086 Posted September 17, 2008 Author Share Posted September 17, 2008 The code didn't like the inlcude, so i chaged the location of the file and now it all works fine Thanks Link to comment https://forums.phpfreaks.com/topic/124646-solved-function-help/#findComment-643807 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.