我有一个熟悉的系统,我为很多人。我花了很多时间手动复制我制作的模板脚本,根据需要进行编辑。导入mysql数据库等等。所以几天前我在想自己,“如果我能填写一个表单,如果给出了正确的mysql信息,并且正确的变量如链接和样式,它会怎样?进入并执行以下任务:1。在指定的mySQL数据库中创建一个特定的表2.实际创建一个类似于以下模板代码的脚本:
<?php
// Creator: Will Renfroe
// All rights Reserved
//Vote Sites and MySQL
$DBNAME="DATABASENAME";
$DBUSER="DATABASENAME";
$DBPASSWORD="PASS";
$DBHOST="DATABASE HOST NAME";
///////////////////
// SCRIPT
///////////////////
mysql_connect($DBHOST, $DBUSER, $DBPASSWORD) or die("<center>Cannot connect to MySQL</center>");
mysql_select_db($DBNAME) or die("<center>Cannot select DB</center>");
/////////
?>
<?php
include("secure.php");
if (getenv(HTTP_X_FORWARDED_FOR)) {
$pipaddress = getenv(HTTP_X_FORWARDED_FOR);
$ipaddress = getenv(REMOTE_ADDR);
} else {
$ipaddress = getenv(REMOTE_ADDR);
}
if(isset($_POST['dovote'])){
check_inject();
//Get user id from session
$userid=secure($_POST["nick"]);
$time=time();
$query=mysql_query("SELECT nick,time FROM votesdb WHERE ip='$ipaddress'");
$checkip=mysql_num_rows($query);
$iprow=mysql_fetch_row($query);
$query=mysql_query("SELECT time FROM votesdb WHERE nick='$userid'");
$checkuser=mysql_num_rows($query);
$userrow=mysql_fetch_row($query);
if ($checkuser){
//if user vote
if ($checkip and $time>$iprow[1]){$canvote=1;}
if (!$checkip and $time>$userrow[0]){$canvote=1;}
}else{
//if user never vote
if ($checkip and $time>$iprow[1]){$canvote=1;}
if (!$checkip){$canvote=1;}
}
//Do Vote
if ($canvote){
$newtime=time()+60*60*24;
if ($checkuser){
//update
mysql_query("UPDATE votesdb SET time=$newtime, ip='$ipaddress', votes=votes+1, flag=flag+1 WHERE nick='$userid'");
}else{
//insert
$query=mysql_query("INSERT INTO votesdb(nick,time,ip,votes,flag) VALUES ('$userid',$newtime,'$ipaddress',1,1)");
}
//Add nick to nicklist table
$query=mysql_query("INSERT INTO nicklist(nick) VALUES ('$userid')");
echo "<font color='green'>Thanks you for a vote. You have been rewarded 10 diamond!</font>";
}else{
echo "<font color='red'>You can only vote every 24 hours to get a reward.</font>";
}
}
?>
<center>
<form target="_blank" action="**WEBSITE URL CAN GO HERE**" method="post"> <input onclick="document.getElementById('vote2').disabled=false" value="NAME OF BUTTON" name="vote1" id="vote1" type="submit" /> </form>
<form method="post" action="**WEBSITE URL CAN GO HERE**" target="_blank"> <input disabled="disabled" name="vote3" value="NAME OF BUTTON" onclick="document.getElementById('vote4').disabled=false" id="vote2" type="submit" /> </form>
</p>
<span class="minecrafttext">Then Enter Your In-Game-Name: </span> <br />
<form method="POST">
<input name="nick" onSubmit="return nameempty();" /> <br/>
<form method="POST">
<input name="dovote" type="submit" value="Get your diamonds!" onclick="document.getElementById('vote4').disabled=false" id="vote4" disabled="disabled"/>
</form>
©<a href="mailto:Willrenfroe@gmail.com">WILLRENFROE</a>
</center>
</body>
它需要请求DATABASENAME,DATABASE,USERNAME,DTABASE,PASSWORD,DATABASE HOST,链接等,任何人都可以帮助我吗?我试过google并且找不到任何东西。
答案 0 :(得分:1)
您可以使用nowdoc将脚本存储在变量中。
然后,您可以执行str_replace
之类的操作来转储您需要的数据。例如,str_replace('DATABASENAME, $DBNAME, $script);
将脚本中的DATABASENAME
替换为$DBNAME
的值。