我正在从PHP代码创建一个图像,它运行良好,但是当我将任何javascript代码放在PHP代码之上时,图像创建者会给出错误
无法显示图像,因为它包含错误。
也不能创造形象。
但是,当我删除header时,它并没有显示任何错误。我试着删除Javascript代码,它又开始工作了。
以下是我的密码。
<script>
var date = new Date();
date.setTime(date.getTime() + 10000);
var expires = "; expires=" + date.toGMTString();
document.cookie = "ctime=" + date.getHours() + expires + "; path = /";
</script>
<?php
include "dbconfig.php";
$city = $_REQUEST['city'];
$query = "SELECT city.cityid, weather.* from city INNER JOIN weather on city.cityid=weather.cityid where weather.date>=curdate() and city.city_name='$city'";
$rs = select($query);
$row = mysqli_fetch_array($rs);
$atmosphere = strtolower($row['atmosphere']);
$minTemp = $row['min_temp'];
$maxTemp = $row['max_temp'];
$temp = $row['temperature'];
$humidity = $row['humidity'];
header('Content-type: image/jpeg');
$font = "Gugi-Regular.ttf";
$fontsize = 30;
if ($atmosphere == 'clear') {
$atmosphere = 'sunny';
}
$weather = "$atmosphere day.";
$im = imagecreatefromjpeg("$atmosphere.jpg");
$orange = imagecolorallocate($im, 9, 78, 188);
imagettftext($im, 30, 0, 130, 50, $orange, $font, $temp);
imagettftext($im, 16, 0, 130, 70, $orange, $font, $weather);
imagettftext($im, 12, 0, 130, 100, $orange, $font, 'min');
imagettftext($im, 12, 0, 180, 100, $orange, $font, 'max');
imagettftext($im, 12, 0, 230, 100, $orange, $font, 'hum');
imagettftext($im, 12, 0, 130, 120, $orange, $font, $minTemp);
imagettftext($im, 12, 0, 180, 120, $orange, $font, $maxTemp);
imagettftext($im, 12, 0, 230, 120, $orange, $font, $humidity);
imagejpeg($im);
imagedestroy($im);
?>我希望在PHP中获得当前的客户端系统时间,这就是为什么我要将javascript代码从cookie中获得PHP时间的原因。
两样都帮我。
发布于 2018-05-11 08:19:46
你能做到的
<?php
$date = date("H");
setcookie("ctime", $date, time() + 10000, "/");
?>而不是这个
<script>
var date = new Date();
date.setTime(date.getTime() + 10000);
var expires = "; expires=" + date.toGMTString();
document.cookie = "ctime=" + date.getHours() + expires + "; path = /";
</script>https://stackoverflow.com/questions/50285677
复制相似问题