Im looking to figure out a way to replace variable inside a php file then send that modified file thru FTP.
I wish to delete items by keyword for each of my clients... so i dont have to log into their websites everytime. I just need to change the value to a variable inside a php file. I'm having trouble escaping out the $ or something... Is there an eaiser way to say (change $variable to $value in $file)? or overwrite a file a specific?
Here is an example of the file i want to modify
<?php
mysql_connect(host,user,pass);
mysql_select_db(dbName);
$keyword = ""; //I want to replace this line
mysql_query("delete from products where product_name like '%$keyword%'");
?>
I want to run a script on my main servers similar to this
<?php
$handle = fopen("keyword_remover.php", "w");
if ($handle) {
while (($line = fgets($handle)) !== false) {
$write_line .= str_replace("\$keyword=\"\";", "\$keyword=\"".mysql_real_escape_string($_POST['keyword'])."\"", $line);
}
} else {
// error opening the file.
}
fputs($handle,$write_line);
fclose($handle);
//make sure that FTP connection is valid
$connection_url = "ftp.".$client_domain;
// Set up a connection
$ftp_conn = ftp_connect($connection_url);
// Login
if (ftp_login($ftp_conn, $client_user, $client_pass))
{
$connected = "1";
}else{
$connected = "0";
}
if($connected == "1")
{
//FTP connection worked, lets push the script and run it!
$local_dir = "keyword_remover.php";
$remote_dir = "remote_path/keyword_remover.php";
ftp_put($ftp_conn, $remote_dir, $local_dir, FTP_ASCII);
$script_url = "http://".$client_domain."//"keyword_remover.php";
scriptHit($script_url); // Hit the script with curl here
sleep(1);
ftp_delete($ftp_conn, $remote_dir);
echo $script." ran on " .$client_domain."<br>";
}else{
echo "Could not connect to FTP: ". $connection_url."<br>".$client_user."<br>".$client_pass;
}
ftp_close($ftp_conn);
?>
Thank you in advanced :)