search
PHP验证码 @符号 Jun 13, 2016 pm 01:30 PM
checkcodequotrandsession

求助 PHP验证码 @符号

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php session_start();
    
    for($i=0;$i<4;$i++){
        @$rand.=dechex(rand(1,15));//前面的这个@符号要是不加,图片就显示不出来。
    }    
    @$_SESSION[check_pic]=$rand; //前面的@符号要是去掉的话这个就会报错 而且全是乱码。 
    $im=imagecreatetruecolor(100,30); 
    
    $bg=imagecolorallocate($im,0,0,0);
    $te=imagecolorallocate($im,255,255,255);
    imagestring($im,5,0,0,$rand,$te);

      header("content-type:image/jpeg");
  imagejpeg($im);
?>




PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php session_start();
    if($_POST[code]){
        if($_POST[code]==$_SESSION[check_pic]){
                echo "验证码正确:".$_SESSION[check_pic];
        }
            else 
        {
                echo "验证码错误";
            
        }
        
    }
?>
  PHP验证码 @符号
验证码:


我现在前面要是不加@符号的话就是报错。下面是错误的提示
Notice: Use of undefined constant code - assumed 'code' in F:\wamp\apps\project\code_sub.php on line 3

Notice: Use of undefined constant code - assumed 'code' in F:\wamp\apps\project\code_sub.php on line 4

Notice: Use of undefined constant check_pic - assumed 'check_pic' in F:\wamp\apps\project\code_sub.php on line 4

加上@符号之后就一切正常了 这是什么错误


------解决方案--------------------
加引号 $_SESSION["check_pic"]

undefined constant是未定义常量的意思,不加引号字串按常量看待
------解决方案--------------------
PHP code
for($i=0;$i<font color="#e78608">------解决方案--------------------</font><br>$rand.=<br><br>这个变量无赋值的情况使用,所以导致notice错误,图像是二进制,notice是文本,二者混合自然导致图片无法显示。<br><br>解决办法:<br>先给$rand赋值<br><br>$rand='';<br><br>
<br><font color="#e78608">------解决方案--------------------</font><br>
PHP code
    session_start();
    $rand = '';
    for($i=0;$i<font color="#e78608">------解决方案--------------------</font><br>
探讨
PHP code

session_start();

for($i=0;$i @$rand.=dechex(rand(1,15));//前面的这个@符号要是不加,图片就显示不出来。
}
@$_SESSION[check_pic]=$rand; //前面的@符号要是去掉的话这个就会报错 而且全是乱码。 ……
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
如何解决 golang 中的 “undefined: rand.Seed” 错误?如何解决 golang 中的 “undefined: rand.Seed” 错误?Jun 25, 2023 am 08:34 AM

在使用Golang进行开发或学习过程中,我们可能会遇到undefined:rand.Seed的错误提示。这个错误通常会在需要使用随机数生成器时出现,因为在Golang中需要先设置一个随机数种子,才能使用rand包中的函数。本篇文章将介绍如何解决这种错误。1.引入math/rand包首先,我们需要在代码中引入math/rand包。在

SpringBoot Session怎么设置会话超时SpringBoot Session怎么设置会话超时May 15, 2023 pm 02:37 PM

问题发现springboot项目生产session-out超时问题,描述下问题:在测试环境通过改动application.yaml配置session-out,经过设置不同时间验证session-out配置生效,于是就直接设置了过期时间为8小时发布到了生产环境。然而中午接到客户反应项目过期时间设置较短,半小时不操作就会话过期需要反复登陆。解决处理开发环境:springboot项目内置Tomcat,所以项目中application.yaml配置session-out是生效的。生产环境:生产环境发布是

php session刷新后没有了怎么办php session刷新后没有了怎么办Jan 18, 2023 pm 01:39 PM

php session刷新后没有了的解决办法:1、通过“session_start();”开启session;2、把所有的公共配置写在一个php文件内;3、变量名不能和数组下标相同;4、在phpinfo里面查看session数据的存储路径,并查看该文件目录下的sessio是否保存成功即可。

session php默认失效时间是多少session php默认失效时间是多少Nov 01, 2022 am 09:14 AM

session php默认失效时间是1440秒,也就是24分钟,表示客户端超过24分钟没有刷新,当前session就会失效;如果用户关闭了浏览器,会话就会结束,Session就不存在了。

Springboot2 session设置超时时间无效怎么解决Springboot2 session设置超时时间无效怎么解决May 22, 2023 pm 01:49 PM

问题:今天项目中遇到了一个设置时间超时的问题,按SpringBoot2的application.properties更改一直不生效。解决方案:server.*属性用于控制SpringBoot使用的嵌入式容器。SpringBoot将使用ServletWebServerFactory实例之一创建servlet容器的实例。这些类使用server.*属性来配置受控的servlet容器(tomcat,jetty等)。当应用程序作为war文件部署到Tomcat实例时,server.*属性不适用。它们不适用,

PHP如何在多个文件中正确地读取和写入Session数据PHP如何在多个文件中正确地读取和写入Session数据Mar 23, 2023 am 11:12 AM

当您在使用PHP会话(Session)时,有时会发现Session在一个文件中可以正常读取,但在另一个文件中却无法读取。这可能会让您感到困惑,因为会话数据应该可以在整个应用程序中共享。本文将解释如何在多个文件中正确地读取和写入PHP会话数据。

Redis的共享session应用如何实现短信登录Redis的共享session应用如何实现短信登录Jun 03, 2023 pm 03:11 PM

1.基于session实现短信登录1.1短信登录流程图1.2实现发送短信验证码前端请求说明:说明请求方式POST请求路径/user/code请求参数phone(电话号码)返回值无后端接口实现:@Slf4j@ServicepublicclassUserServiceImplextendsServiceImplimplementsIUserService{@OverridepublicResultsendCode(Stringphone,HttpSessionsession){//1.校验手机号if

PHP如何处理微信小程序中的session问题PHP如何处理微信小程序中的session问题Jun 02, 2023 pm 03:40 PM

近年来,微信小程序风靡全球,已经成为了许多企业和个人开发者的首选平台。在小程序的开发中,我们经常会遇到session问题,也就是如何在小程序中保存用户登录状态。这个问题对于网站开发者来说并不陌生,但在小程序中却有些不同。本文将介绍如何使用PHP解决微信小程序中的session问题。一、小程序登录过程概述小程序的登录流程与网站的登录流程类似,分为以下几个步骤:

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function