如何用file_put_contents()写变量值? [英] how to write variables value with file_put_contents()?
问题描述
我试图使用 file_put_content
把一个变量值放到另一个php文件中。
以下代码将解释:
将数据写入php的文件:
<?php
require('conf_2135432135435135412312534.php');
$ F_name = $ _ POST ['F__name'];
$ L_name = $ _ POST ['L__name'];
$ E_mail = $ _ POST ['Email'];
$ GDI_user = $ _ POST ['GDIusername'];
$ ip = $ _ SERVER ['REMOTE_ADDR'];
$ C_date = date(F j,Y,g:i a);
mysql_connect($ hostname,$ username,$ password)或die(mysql_error());
mysql_select_db($ dbname)或者死(mysql_error());
$ b $ sql =INSERT INTO $ usertable(F_name,L_name,Email,GDI_username,Registration_IP,Date_registered)VALUES('$ F_name','$ L_name','$ E_mail', '$ GDI_user','$ ip','$ C_date');
if(!mysql_query($ sql)){
die('Error:'。mysql_error());
$ b $ get_id = mysql_query(SELECT * FROM $ usertable WHERE。GDI_username ='$ GDI_user');
while($ id_check = mysql_fetch_array($ get_id)){
$ UNQ_ID = $ id_check [Unique_id];
}
$ src =/ home / files / 1/741 / html / WP / Default_files;
$ dest =/ home / files / 1/741 / html / WP / $ GDI_user;
echo$ GDI_user / config.php;
shell_exec(cp -r $ src $ dest);
$ b file_put_contents(/ home / files / 1/741 / html / WP / $ GDI_user / config.php,<?
$ affiliate_reference =$ UNQ_ID ;
echo $ UNQ_ID;
?>');
?>
^^简短说明代码的作用:^^
<1>)从html表格获取信息
2)将数据插入到数据库中
$ b $ )从数据库中获取一个Unique_id号码。
4)创建一个包含所有内容的文件夹副本( Default_files
)
<5>)重复的文件夹被赋予了一个输入到HTML表单中的名字$ b $ (config.php)
输出(config.php) )应该包含:
<
$ affiliate_reference =2154216354154; //<<<<那只是一个例子
echo 2154216354154;
?>
相反,这是显示的内容:
<
$ affiliate_reference =$ UNQ_ID;
echo $ UNQ_ID;
?>
完全丢在这里。任何帮助,将不胜感激。
您正在使用'
定义字符串,这意味着该值将保持不解析。但是,这里的技巧是你想要解析$ UNQ_ID,但是你希望 $ affiliate_reference
保持原样。这意味着你必须转义或手动连接
我会用这个:
'< ;?
$ affiliate_reference ='。$ UNQ_ID。';
echo'。$ UNQ_ID。';
$ b $>'
注意,我使用单引号大部分的字符串。这是有目的的,你不希望输出 $ affiliate_reference
。你只想把$ UNQ_ID变成它的字符串等价。你的另一个选择是使用并转义
$
:
< ;?
\ $ affiliate_reference ='。$ UNQ_ID。';
echo'。$ UNQ_ID。';
$ b?>
请注意 我一般比较喜欢第一个颜色语法的荧光笔会使这一点非常明显(甚至注意到SO是如何处理的),而第二个例子则是让荧光笔釉上了整个东西,这是一个偏好,但它是一个重要的例子。 当然,总会有这样的愚蠢: 其次是 仅在没有人的情况下使用喜欢。 Have been trying to figure this out all day assuming its just a small error..... I'm trying to use the Code below will explain: File that writes the data into the php: ^^Short explanation of what that code does:^^ 1.) Takes info from a html form 2.) INSERTS the data into a DB 3.) Fetches a Unique_id number from the DB 4.) Makes a copy of a folder with all the contents in it ( 5.) The duplicate folder is given a name of what was entered into the HTML form 6.) Writes into a file contained in the duplicate folder (config.php) What the output (config.php) SHOULD contain: Instead, This is what's showing up: completely lost here. Any help would be much appreciated. You're using I would use this instead: Notice, I am using the single quote for the majority of the string. This is purposeful, you don't want the Note the I generally prefer the first way, color syntax highlighters will make that very obvious (even notice how SO handles it), while the second example causes highlighters to glaze over the whole thing. It is a preference, but it is an important one. Of course, there is always the silly: followed by Use that only with people you don't like. 这篇关于如何用file_put_contents()写变量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! \\ \\ code>在$ affiliate_reference前面转义
$
。
$ b
$ a ='$';
< ;?
$ {a} affiliate_reference ='。$ UNQ_ID。';
echo'。$ UNQ_ID。';
$ b?>
file_put_content
to put a variables value into another php file.. <?php
require ('conf_2135432135435135412312534.php');
$F_name =$_POST['F__name'];
$L_name =$_POST['L__name'];
$E_mail =$_POST['Email'];
$GDI_user =$_POST['GDIusername'];
$ip=$_SERVER['REMOTE_ADDR'];
$C_date = date("F j, Y, g:i a");
mysql_connect($hostname,$username,$password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$sql = "INSERT INTO $usertable (F_name, L_name, Email, GDI_username, Registration_IP, Date_registered) VALUES ('$F_name', '$L_name', '$E_mail', '$GDI_user', '$ip', '$C_date')";
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
$get_id = mysql_query("SELECT * FROM $usertable WHERE ". "GDI_username = '$GDI_user'");
while($id_check = mysql_fetch_array($get_id)) {
$UNQ_ID = $id_check["Unique_id"];
}
$src = "/home/files/1/741/html/WP/Default_files";
$dest = "/home/files/1/741/html/WP/$GDI_user";
echo "$GDI_user/config.php";
shell_exec("cp -r $src $dest");
file_put_contents("/home/files/1/741/html/WP/$GDI_user/config.php",'<?
$affiliate_reference = "$UNQ_ID";
echo $UNQ_ID;
?>');
?>
Default_files
)<?
$affiliate_reference = "2154216354154"; //<<<thats just an example number
echo 2154216354154;
?>
<?
$affiliate_reference = "$UNQ_ID";
echo $UNQ_ID;
?>
'
to define the string, this means that the value will be left unparsed. The trick here, though, is that you want $UNQ_ID parsed, but you want $affiliate_reference
left as is. This means you have to escape or manually concatenate'<?
$affiliate_reference = "'.$UNQ_ID.'";
echo '.$UNQ_ID.';
?>'
$affiliate_reference
to be output. You only want $UNQ_ID turned into its string equivalent. Your other option is to use "
and escape the $
:"<?
\$affiliate_reference = "'.$UNQ_ID.'";
echo '.$UNQ_ID.';
?>"
\
to escape $
in front of $affiliate_reference.$a = '$';
"<?
${a}affiliate_reference = "'.$UNQ_ID.'";
echo '.$UNQ_ID.';
?>"