OK, So I have a PHP script that I got from another site. In that script there is a variable in a config.php file. How easy would it be to replace that variable With information from a form on the site? (The Variable in config.php looks like this)... $variable_name = "THIS IS WHAT I WANT TO REPLACE"; The config file is called every time the script is run, Ideally, I'd like someone to be able to input their variable, then have a cookie put onto their machine with the information they enter into the form, so that they don't have to keep adding the information to the form. I think that makes sense...
the config file is universal and not user dependent. so how can it be related to cookie? u were indeed confusing. the first part was ok, the second part was ok too, but together they re not at all ok. cud u explain what u exaclty want? i mean.. is it the config file be edited with the form variable value a user inputs (but this will refelet for every other user) or is it that u store a value your user enter in cookie?
Sounds like you have a file that is globally included and you aren't talking about php.ini Try out this: if(!($_POST['post_variable_name'] == NULL)){ $variable_name = $_POST['post_variable_name']; } else { $variable_name = 'original_value'; } Code (markup): D'oh! I just saw the cookie piece. I don't know the call to get a cookie variable, but just replace $_POST['post_variable_name'] as appropriate. I'm thinking something along the lines of: $cookievar = GetCookie('cookiename') if(!($cookievar ==NULL)){ $variable_name = $cookievar; } else { $variable_name = 'original_value'; } Code (markup): Now I'm not sure that GetCookie is actually a function, but IIRC it's something close to that.
You can get cookie variables from the global $_COOKIES array, so you could use if ( isset($_COOKIE['cookiename']) ) { $variable_name = $_COOKIE['cookiename']; } else { $variable_name = 'default'; } Code (markup): cheers johnt
Hehe - this place rules... OK, so let me be a little more clear (If I can) On index.php, I have a search function. This search function uses the google API, which is currently hard coded into the config.php file(where I mentioned $variable_name = "THIS IS WHAT I WANT TO REPLACE". I want users to be able to enter their own API key when they visit index.php, but only have to enter it once in order to be able use the search function multiple times... This is why I guessed a cookie would be the best option... Does that make sense now? (I hope so) I'm looking at the code aove now - will this do the job? (You must spread some Reputation around before giving it to nevetS again. Sorry)
The above code will kind of do the job, but you'll want to replace $variable_name='default'; with some code to prompt the user for their API key and then store it in a cookie.
Sorry, I'm lost then... In the index.php file, what do I use to catch the information input in the form... Something like... <form method="POST" action="config.php"> <input name="api" type="text" size="20" class="whatever"> <input name="Submit" type="submit" class="whatever"> </p> And in the config.php, I add if(!($_POST['post_variable_name'] == NULL)){ $variable_name = $_POST['api']; } else { $variable_name = 'original_value'; } if ( isset($_COOKIE['apicookie']) ) { $variable_name = $_COOKIE['apicookie']; } else { $variable_name = 'default'; } It that anywhere near right? Sorry, I'm really shit at this...
<?php ob_start(); include "config.php"; if ( isset($_REQUEST['submit']) ) { if ( !isset($_COOKIE['variable_name']) ) { $variable_name = $_REQUEST['variable_name']; setcookie('variable_name', $variable_name); } else { $variable_name = $_COOKIE['variable_name']; } ob_end_flush(); // Process the rest of your script } else { ?> <form name="form1" method="POST" action="index.php"> <!-- Any form elements you need --> <? if ( !isset($_COOKIE['variable_name']) ) { echo "<input type='text' name='variable_name' size='20'>\n"; } ?> <input name="submit" value="Submit" type="submit"> <? } ?> PHP: I think that should do it when you add the rest of your script bits in cheers John