0
我一直在想弄清楚如何完成這個PHP腳本,我認爲它會真的幫助我和其他人試圖創建一個保存QR碼的腳本然後將它們發送給創建它們的人。我目前試圖做的是創建一個QR碼生成器,通過電子郵件向個人發送一個由姓名和電子郵件信息信息動態生成的QR碼。基本上,這裏的目標是在URL中執行PHP Get Request以在站點上顯示用戶的動態PHP頁面。來自Google Chart的QR碼生成器的圖像動態命名
請讓我知道如果這沒有意義,我真的很感激任何和所有的幫助,並覺得這是一個問題,其他人可能還需要在未來的幫助!
<?php
if (isset($_POST['submit'])) {
$hostname = 'localhost';
$user = 'username';
$pass = 'password';
$dbase = 'database';
$connection = mysql_connect("$hostname" , "$user" , "$pass")
or die ("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");
function clean($var)
{
$dirtystuff = array("\\", "/", "*", "'", "=", "#", ";", "<", ">", "+", "%");
return mysql_real_escape_string(str_replace($dirtystuff , "" , $var)) ;
}
$_POST = array_map("clean", $_POST);
$name = $_POST['name'];
$email = $_POST['email'];
$sql = "INSERT INTO qrdb (Name, Email)
VALUES ('$name', '$email');";
mysql_query($sql) or die("Couldn't run the query: " . $sql . " - " . mysql_error()
);
mysql_close();
}
$filename = "$HELPWITHVAR";
$width = 400;
$height = 400;
if (!file_exists($filename))
{
$url = urlencode("DynamicURLHEREWithNameAndEmailInfoInAGetRequestFormat");
$qr = file_get_contents("http://chart.googleapis.com/chart?chs=
{$width}x{$height}&cht=qr&chl=$url");
file_put_contents($filename, $qr);
}
echo "<img src=\"$filename\" width=\"$width\" height=\"$height\" alt=\"Scan my QR !\"
/>";
$to = "$_POST['email']";
$subject = "QR Code for you!";
$message = "
<html>
<body>
<p>Here is your QR Code!</p>
<p><?php echo $filename ?></p>
</body>
</html>";
$headers .= 'From: <[email protected]>' . "\r\n";
mail($to,$subject,$message,$headers);
?>