ChayaCooper Posted December 10, 2012 Share Posted December 10, 2012 I know this is a really basic question, but I'm still a real php noob. I want to move $salt to the config.php file, but I'm not sure how to call the variable correctly so the page can use it. I tried this: require_once('config.php); $salt = loadSaltFromConfig(); I'm assuming that I need to declare loadSaltFromConfig somewhere, but I'm not quite sure what that would need to be. Quote Link to comment https://forums.phpfreaks.com/topic/271838-how-do-i-get-salt-when-its-in-the-configphp-file/ Share on other sites More sharing options...
MDCode Posted December 10, 2012 Share Posted December 10, 2012 If you require the file, all variables set in the file will be available by just calling that variable. Quote Link to comment https://forums.phpfreaks.com/topic/271838-how-do-i-get-salt-when-its-in-the-configphp-file/#findComment-1398612 Share on other sites More sharing options...
ChayaCooper Posted December 10, 2012 Author Share Posted December 10, 2012 I'll try that again :-) I thought that should be the case, but when it didn't work I figured I must be doing something wrong ;-) Just to make sure that I'm not missing something I'm declaring in config.php $salt = "XYZ"; // 10 digit string. Then if I've created a connection to config.php in the other file I can just use it like this: '".sha1($salt + $_POST['password'])."' Quote Link to comment https://forums.phpfreaks.com/topic/271838-how-do-i-get-salt-when-its-in-the-configphp-file/#findComment-1398621 Share on other sites More sharing options...
ChayaCooper Posted December 10, 2012 Author Share Posted December 10, 2012 What is the correct way to set the path to a file when it's in a subfolder? Adding the folder name like this didn't work require_once('secure_folder/config.php'); Quote Link to comment https://forums.phpfreaks.com/topic/271838-how-do-i-get-salt-when-its-in-the-configphp-file/#findComment-1398623 Share on other sites More sharing options...
jazzman1 Posted December 11, 2012 Share Posted December 11, 2012 Where are you? echo getcwd() . "\n"; Quote Link to comment https://forums.phpfreaks.com/topic/271838-how-do-i-get-salt-when-its-in-the-configphp-file/#findComment-1398637 Share on other sites More sharing options...
ChayaCooper Posted December 11, 2012 Author Share Posted December 11, 2012 I'm assuming that you're asking where the document is located? 'secure_folder' is located inside the folder 'demo', and I need to reference it from files which are either in the 'demo' or the parent directory. Quote Link to comment https://forums.phpfreaks.com/topic/271838-how-do-i-get-salt-when-its-in-the-configphp-file/#findComment-1398639 Share on other sites More sharing options...
jazzman1 Posted December 11, 2012 Share Posted December 11, 2012 Ok, put it echo getcwd() . "\n"; on the top of the files - config.php and the parent one and give us results. Quote Link to comment https://forums.phpfreaks.com/topic/271838-how-do-i-get-salt-when-its-in-the-configphp-file/#findComment-1398641 Share on other sites More sharing options...
Love2c0de Posted December 11, 2012 Share Posted December 11, 2012 You can also use: $dir_name = dirname(__FILE__): Once you have the string directory, you can then search the directory for example: $files = scandir($dir_name); echo "<pre>"; print_r($files); echo "</pre>"; Hope it helps. Regards, AoTB. Quote Link to comment https://forums.phpfreaks.com/topic/271838-how-do-i-get-salt-when-its-in-the-configphp-file/#findComment-1398642 Share on other sites More sharing options...
ChayaCooper Posted December 11, 2012 Author Share Posted December 11, 2012 @jazzman1: Here are the results from the 3 folders: Parent Directory /home4/clickfi4/public_html 'demo' folder /home4/clickfi4/public_html/demo 'secure_folder' subfolder /home4/clickfi4/public_html/demo/secure_folder Quote Link to comment https://forums.phpfreaks.com/topic/271838-how-do-i-get-salt-when-its-in-the-configphp-file/#findComment-1398648 Share on other sites More sharing options...
jazzman1 Posted December 11, 2012 Share Posted December 11, 2012 (edited) I think your directories looks good. Make a simple test for me> Create a new file in directory- "/home4/clickfi4/public_html/demo" and named it - debug.php. On the top of your config.php file put it - echo 'test'. A config.php must locate in "/home4/clickfi4/public_html/demo/secure_folder" In a debug.php file copy/paste next code: <?php error_reporting(E_ALL); require_once 'secure_folder/config.php'; Edited December 11, 2012 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/271838-how-do-i-get-salt-when-its-in-the-configphp-file/#findComment-1398658 Share on other sites More sharing options...
ChayaCooper Posted December 11, 2012 Author Share Posted December 11, 2012 Did that :-) I added to the config.php echo ("test"); In 'demo folder' - debug.php <?php session_start(); error_reporting(E_ALL); require_once 'secure_folder/config.php'; ?> And when I go to http://www.click2fit.com/demo/debug.php it echos 'test' :-) Quote Link to comment https://forums.phpfreaks.com/topic/271838-how-do-i-get-salt-when-its-in-the-configphp-file/#findComment-1398663 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.