首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果页面上有javascript代码,则PHP映像创建无法工作

如果页面上有javascript代码,则PHP映像创建无法工作
EN

Stack Overflow用户
提问于 2018-05-11 05:39:19
回答 1查看 62关注 0票数 0

我正在从PHP代码创建一个图像,它运行良好,但是当我将任何javascript代码放在PHP代码之上时,图像创建者会给出错误

无法显示图像,因为它包含错误。

也不能创造形象。

但是,当我删除header时,它并没有显示任何错误。我试着删除Javascript代码,它又开始工作了。

以下是我的密码。

代码语言: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时间的原因。

两样都帮我。

EN

回答 1

Stack Overflow用户

发布于 2018-05-11 08:19:46

你能做到的

代码语言:javascript
复制
<?php
$date = date("H");
setcookie("ctime", $date, time() + 10000, "/");
?>

而不是这个

代码语言:javascript
复制
<script>
    var date = new Date();
    date.setTime(date.getTime() + 10000);
    var expires = "; expires=" + date.toGMTString();
    document.cookie = "ctime=" + date.getHours() + expires + "; path = /";
</script>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50285677

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档