Current location: Hot Scripts Forums » Programming Languages » PHP » POSTing to PHP, - making a install script


POSTing to PHP, - making a install script

Reply
  #1 (permalink)  
Old 03-30-05, 05:55 AM
urlguy urlguy is offline
Newbie Coder
 
Join Date: Feb 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
POSTing to PHP, - making a install script

Hi,

I have made this script, which include a config file (config.php)
where the user has to insert its own variables to make it work
a simple look of the config.php would be like
<?
$domain="domain.com";
?>

But I would like to add another script to this, like Install.php, where user could go thru each setting there from and fill in from web, instead of opening it with notepad and editing..

I have tried a html POST command like the regular one.. But when I try to do like POST to my config.php and the post value are "domain" to edit the current ones set in config.php, or update if setting not set, it just gives me "internal server error", and I have tried this at 3 different places I got hosting so its most likely a script error.


Basicly.. I just need a script or code that allows me to POST to (edit) or fill in values in my config.php which havent been set



Really hope anyone got a solution for this.. havent bn able to find it anywhere yet =|
Thx in advance
Reply With Quote
  #2 (permalink)  
Old 03-30-05, 09:55 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
you have to deal with this config.php as any plain text file, and open it for rewrite or save it in a variable..
the idea is to make your config.php as a template like for example:
PHP Code:

<?php

$domain    
'::DOMAIN::';
$password '::PASSWORD::';
?>
and then with your install (with POST method), replace the values that the user enters with a simple str_replace() like in our example:
PHP Code:

$content = '<?php

$domain    
= \'::DOMAIN::\';
$password = \'::PASSWORD::\';
?>'
;

$change_from[0] = '::DOMAIN::';
$change_from[1] = '::PASSWORD::';

$change_to[0] = trim($_POST['domain']);
$change_to[1] = trim($_POST['password']);  

$content str_replace($change_from$change_to$content);

//WRITE THE FILE HERE
but you have to be careful and check for magic quotes or your file will not work..
HTH
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]

Last edited by NeverMind; 03-30-05 at 10:01 AM.
Reply With Quote
  #3 (permalink)  
Old 03-30-05, 10:30 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
and because i can predict your next question, here is the function:

PHP Code:

<?

function check_magic_quotes($string) {
if (!
get_magic_quotes_gpc()) $string addslashes($string);
return 
$string;
}
?>
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #4 (permalink)  
Old 03-30-05, 01:57 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
actually, it should be the opposite!
if magic quotes are on, we stripslashes() because you are not preparing the data for SQL use
and to make this function useful in this situation, I made these changes:
PHP Code:

function check_magic_quotes()

{
   if (
get_magic_quotes_gpc())
       foreach (
$_POST as $field => $value)
           
$_POST[$field] = stripslashes($value);

just call this function before $change_to[]s
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #5 (permalink)  
Old 03-30-05, 04:48 PM
urlguy urlguy is offline
Newbie Coder
 
Join Date: Feb 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
thanks for your replies ppl..
tho I didnt quite understand the magic quote part as im kinda newb to php, Ill try sort it out.. didnt get the top part either hehe =\

Could anyone just give me a short explenation on where in the above code I should enter the variables to be edited? and where I specify file to be edited?

Any help are greatly apprecciated,
Anders.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
Need PHP Script Install allbiz Job Offers & Assistance 1 03-24-05 08:07 PM
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 12:12 AM
Run PHP Script Within PHP Script Reg PHP 1 06-29-04 09:09 AM
100 Web Templates & 10 PHP Scripts for sale! HostersUK.co.uk General Advertisements 0 01-10-04 12:31 AM


All times are GMT -5. The time now is 05:39 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.