PDA

View Full Version : Php Important Help Needed


ronit1
08-20-2006, 04:54 PM
Ill Explain My Question

For Eg

i have a file name settings.php

in that i put a code

$sitename = "My Site Name"

now if the script user wants to change the site name he has to open config.php and edit it

but wat i want is an option in admin panel where it says

Enter Your Site Name :

And wat ever u enter there is saved in the config

how do i do it can some post an example code

thanks in advance :thumbsup:

kaydara
08-20-2006, 05:04 PM
why dont you go pick the site name to a sql table ? and set the name in that table too

ronit1
08-20-2006, 05:31 PM
why dont you go pick the site name to a sql table ? and set the name in that table too


coz i m building a flat file application

Crowds
08-20-2006, 06:43 PM
You would need to use fopen..

Say in your admin area for set up you had a form element like (to enter the name of the site)
<form action="setup.php" method="get">
<input name="site" type="text" />
<input name="submit" type="submit" value="Submit" />

</form>

then in your setup.php page (or whatever you call it) you would need...


<?
//get the site name varible from the form
$site = $_GET['site'];

$fp = fopen('config.php', 'w') ;

//echo out any errors
if(!$fp)
{
echo "Could not open Admin Config";
exit;
}

// set the $string variable to write the varible from the form to your config page
$string = '<?php
/* config.php
store all your setup details here
*/
$sitename = "' . $site . '"; ?>';

flock($fp, LOCK_EX);
fputs($fp, $string);

flock($fp, LOCK_UN);

fclose($fp); //fclose to close the file.
// echo success
echo "<br><br>site name value added as...";
echo "$site<br>";
?>


This requires the correct read/write setting on your server so it can create a config.php page with the details you enter.
then you can include the file wherever needed and echo out your site name

<?
include "config.php";
echo "$sitename";
?>

At the top of the php forum there is a good tutorial about this in the faq area
http://www.codingforums.com/showthread.php?t=36143

Spookster
08-21-2006, 01:17 AM
In the future, please use a more descriptive subject when posting a question. See posting guidelines. (http://www.codingforums.com/postguide.htm)