|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
PHP fwrite() with executed and none executed variables
PHP Code:
Well as you can see this is really simple code its almost doing what i want. Basically everything between the single quotes in the second line $towrite does write into the specified file and all works. What im having problems with is getting the $host variable to execute as a variable and not text what i want it to do is write something like this into the file Code:
<?php $dbhost = "hostname" ; ?> but its writing this Code:
<?php $dbhost = "$host" ; ?> I have tried all sorts of variations of double quoted and single quotes with and without periods around the variable $host but i just cant seem to get it to execute how i want, the only time it did execute was when i enclosed it all in doublequotes, but as would be expected this executed both variables and i dont want the first variable to execute. Any clues? Please excuse my edit.. mr fat fingers decided to pay me a visit ;op SOLVED:: May not be pretty but it works.. PHP Code:
__________________
If i went into too much detail or assumed this was what you meant, well thats just how i thought you wanted it Last edited by phpwebmaster : November 3rd, 2009 at 05:28 AM. |
|
#2
|
||||
|
||||
|
Does this not give you what you want?
PHP Code:
|
|
#3
|
|||
|
|||
|
Quote:
no it doesn't, im using this to set up a variable as part of an install script im setting up. it needs to write this to the file: <?php $dbhost = "localhost" ; ?> Basically write the first variable without executing it and then execute the second variable, i struggled to get the double quotes and execute the variable all at the same time, after dome thought and a lot of fiddling i figured on using double quotes but then stopping the first variable from executing by single quoting. it, like i say it dont look pretty but its working. where i think your code would write: <?php $dbhost = localhost ; ?> This would probably be fine except for the password part where cpanels pass generator uses characterd that unquoted would break the code. |
|
#4
|
||||
|
||||
|
This
PHP Code:
Outputs Code:
<?php $dbhost = "localhost" ; ?> This PHP Code:
Outputs Code:
<?php $dbhost = 'localhost' ; ?> This PHP Code:
Ouputs this Code:
<?php $dbhost = 'localhost' ; ?> This PHP Code:
Ouputs this Code:
<?php $dbhost = "localhost" ; ?> This PHP Code:
Ouputs this Code:
<?php $dbhost = "localhost" ; ?> is this not what you want? Last edited by Northie : November 3rd, 2009 at 08:53 AM. |
|
#5
|
||||
|
||||
|
Out of interest, why are you doing this?
I hope you're not going to be eval()ing it at any point This all looks very insecure..... |
|
#6
|
||||
|
||||
|
Quote:
PHP Code:
PHP Code:
__________________
IkoTikashi - ikotikashi.de |
|
#7
|
|||
|
|||
|
Quote:
i was just thinking i didnt try it as id already resolved it in my own way, i will try it out anyway as its only a small change to what i have and its easier to read and understand, $host is going to be set by the user installing the script, its not much really but i wanted to make the install easier. uploading the database, creating configurations file with settings and that sort of thing. so far its going well, its taken me all day to work it all out but im happy with the results. (so far) lol |
|
#8
|
|||
|
|||
|
Quote:
You have a point with it lookin insecure, at the moment it is, i have only been testing it in an unlinked directory as i wanted to get it working. its taking information from a form, using that info to create a database with pre compiled queries, and write the configuration file for the site. The database information is stored in a config file outside of the web path once its written to the file and the database has installed the installation directory is to be deleted. either by way of a link in the installation or manually, ive yet top look into all that. As for security script wise, i know i have a long way to go before this could even possibly be thought about using properly, but in testing its working fine, obviously im not trying to attack my server tho lol |
|
#9
|
||||
|
||||
|
Just as an aside, this is what you were looking for:
PHP Code:
This is also the wrong way to do things, you should be using an ini-file format (see parse_ini_file) or a database. -Dan
__________________
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002 Think we're being rude? Please read this. Trying to argue intelligently? Please read this. |
|
#10
|
|||
|
|||
|
Quote:
Thanks dan, the ini-file doesnt appear at least on the surface to be what im looking for. If im getting what its for correct, i know the php ini can contain mysql connection information, tho the last time i installed php it was advised against doing so. im not trying to make a 1 system program i wouldnt bother wasting my time doin all this work for just 1 install, this is mean to be a reusable installation across different sites, even servers if need be |
|
#11
|
||||
|
||||
|
Not php.ini, but a "general" .ini file for configuring your site, like config.ini, database.ini etc.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > PHP fwrite() with executed and none executed variables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|