drvonr6573 2016-05-03 13:05
浏览 37

使用GD库创建验证码,只返回一个数字

I am new to PHP. When I check index.php it doesn't generate random number, rather it generates sames number all the time when refreshing the page. I use XAMPP v3.2.2 and GD library seems to be pre-installed, so what seems to be problem.

My index.php:

<?php
    ob_start();
    $_SESSION['secure'] = rand(1000,9999);
?>
<img src="generate.php"/>

My generate.php:

<?php 
    session_start();
    header('content-type = image/jpeg');
    $text = $_SESSION['secure'];

    $font_size = 30;

    $image_width = 300;
    $image_height = 100;

    $image = imagecreate($image_width, $image_height);
    imagecolorallocate($image, 211, 211, 211);
    $text_color = imagecolorallocate($image, 0, 0, 0);
    imagettftext($image, $font_size, 0, 30, 55, $text_color, 'font.ttf',   $text);
    imagejpeg($image);
?>
  • 写回答

1条回答 默认 最新

  • doutuobao4004 2016-05-03 13:28
    关注

    It is a minor spelling mistake:

     header('Content-Type: image/jpeg'); 
    

    Instead of

    header('content-type = image/jpeg');
    

    http://php.net/manual/en/function.imagettftext.php

    Hope to have helped you with this.

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向