lifetalk Posted September 7, 2007 Share Posted September 7, 2007 Ok, So, am just starting out on PHP, and needed a help on a specific feature. Suppose, a script has a config.php file, which has particular variables, that are being used in multiple .php pages. Now, if I wanted to update something in the config.php file, i would normally have to get it from the server (FTP, Web), and then edit, and re-upload... right? So, what my question here is, is there any way, that I could setup another .php file, with an interface, and fields, which when filled, and submitted, would in turn, edit the config.php file, and automatically update it? And if yes, can someone point me over to a tutorial, or outline the basics for doing it? The config.php file has about 2 or 3 variables, so, is pretty small... Here's the contents of the config.php file (does not contain any sensitive info though) <?php //Config file for ShoutLoud proxy. Make sure you edit the content when the need arises. //Do not edit any of the $variables.. don't ask me why //Sponsored Links area... edit/embed the links here.. $sponsor_links = ' <p><a href="http://www.stackians.com">Stackians.Com</a></p> <p>Current Price: <b>$3</b> per month.</p>'; //And here is the area for Featured Links $featured_links = ' <ul> <li class="first"><a href="#">This Is A Test Link</a></li> <li><a href="#">This Is A Test Link</a></li> <li><a href="#">This Is A Test Link</a></li> </ul>'; //Yea, that is the end of this simple config file. //Basically.. it is all HTML.. ... so have fun.. and get back at me incase of problems. //Stop editing below this line //this is the paypal button code for sponsored links area (green area) //Change the email to your PP email, and if you want to change the price.. change that too.. $paypal_button = ' <center><form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="knowme640@yahoo.com"> <input type="hidden" name="item_name" value="Shoutloud Sponsored Link"> <input type="hidden" name="amount" value="3.00"> <input type="hidden" name="no_shipping" value="1"> <input type="hidden" name="return" value="http://www.shoutloud.info/sponsor-advertise.php"> <input type="hidden" name="cancel_return" value="http://www.shoutloud.info/index.php"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="lc" value="IN"> <input type="hidden" name="bn" value="PP-BuyNowBF"> <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit"> <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form></center>'; ?> Hope I explained my problem/query... Any help appreciated Quote Link to comment Share on other sites More sharing options...
lemmin Posted September 7, 2007 Share Posted September 7, 2007 I would just set config.php up to change the variables if a certain variable is set in the $_POST or $_GET arrays. All you would have to do is send the form to config.php. There is quite a bit of exploiting someone could do with this kind of a system, though, so you should make sure it is secure. Quote Link to comment Share on other sites More sharing options...
lifetalk Posted September 7, 2007 Author Share Posted September 7, 2007 Thanks for the quick reply... could you just give me a slight coded example that i can use.. and probably a tip on how would I go about securing it? Thanks Quote Link to comment Share on other sites More sharing options...
lemmin Posted September 7, 2007 Share Posted September 7, 2007 Inside config.php, have some code like: if isset($_POST['var1']) $var1 = $_POST['var1']; You could have one of those for each of your variables. Then in another file, have a form that posts to config.php: <form method=post action="config.php"> <input type=text name="var1"> <input type=submit> </form> Upon submitting that form, it should set the respective variable in config.php to whatever you input. If no user has access to this file, there shouldn't be a way for anyone to hack it, but if they somehow knew the name of the variable ("var1" in this example), that would be bad. The security of it really depends on how you plan to use the file. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted September 7, 2007 Share Posted September 7, 2007 So what you're saying is that the user should have to fill out and submit this form before every page request? A config file is meant to be included(), which means no one is posting to it. You need to learn how to do the following. A) Create a form and process it on the server. B) Create and write to a file in PHP, the functions fopen(), fwrite(), fclose() will be helpful here. C) Combine your knowledge from A and B to process the form and rewrite the existing config.php based on what the user submitted in the form. Quote Link to comment Share on other sites More sharing options...
lemmin Posted September 7, 2007 Share Posted September 7, 2007 Wow, you're right, my way wouldn't have actually saved the variable. I don't know what I was thinking. Quote Link to comment Share on other sites More sharing options...
lifetalk Posted September 8, 2007 Author Share Posted September 8, 2007 So what you're saying is that the user should have to fill out and submit this form before every page request? A config file is meant to be included(), which means no one is posting to it. You need to learn how to do the following. A) Create a form and process it on the server. B) Create and write to a file in PHP, the functions fopen(), fwrite(), fclose() will be helpful here. C) Combine your knowledge from A and B to process the form and rewrite the existing config.php based on what the user submitted in the form. Exactly.. that is what I need to do.. Here's what I want to do... I've got a newsletter script setup. Now, it did not have a config.php file. I created one, the one that I've shown here. So, basically, what I want to do, is to be able to edit it via the admin panel of the newsletter. (the admin panel has authorization built into it, so i believe the security issue is somewhat resolved, since everyone will not have access to the script) However, as I said, I am completely noob in PHP, and just have a very very basic knowledge.. limited to whatever I've made in config.php I've no idea about fopen() etc commands... Which is why I asked the question here. I'd love to learn PHP, however, I guess it will be some time.... Can anyone recommend a good book I could start with? Thanks to lemmin too for helping me out And thanks to all those who post here and help out Quote Link to comment Share on other sites More sharing options...
jscix Posted September 8, 2007 Share Posted September 8, 2007 Most Oreilly books are good, generally look for 'introduction' books, try to avoid the 'learn php in 24 hours' type books. they are trash. good luck. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 8, 2007 Share Posted September 8, 2007 use a database Quote Link to comment Share on other sites More sharing options...
lifetalk Posted September 8, 2007 Author Share Posted September 8, 2007 Most Oreilly books are good, generally look for 'introduction' books, try to avoid the 'learn php in 24 hours' type books. they are trash. good luck. The sticky at PHPFreaks says that Sams Learn PHP in 24hours is very good... and you say that those types are trash :S i guess i'll go with both Quote Link to comment Share on other sites More sharing options...
jscix Posted September 8, 2007 Share Posted September 8, 2007 In my experience* they are trash. Most of the 'in 24 hour' books I've read, tell you how to get things done but lack any detailed description of what your actually doing. Sure you might be able to copy down the code, and have a working guestbook.. but do you understand how each part works and why it works? What if you run into an error? It's always best to understand what your doing. (I haven't actually read that sams book, though.. it may be good.) Quote Link to comment Share on other sites More sharing options...
lifetalk Posted September 8, 2007 Author Share Posted September 8, 2007 So, I guess I'll go with books that are introductory, and go in depth, and have detailed description and explanation about PHP and various functions. thanks for the help jscix Quote Link to comment 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.