Jump to content

[SOLVED] Function help


adam291086

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.