验证码不在模型视图控制器中工作

时间:2013-10-24 13:08:09

标签: php html captcha

我想在我的应用程序中使用验证码。但它不起作用。这是我的目录结构。

  

ROOT

     
    

应用

         

模型

         

view< == index.php(默认主页)位于视图文件夹

中          

控制器

         

包括< == image.php(captha图像生成器)存在于目录

中   

每当我在主页内使用IMG标签时,验证码图像都不会显示。即使我在使用之前测试了验证码,它工作正常,但不在我的网站。我正在使用Netbeans 7.4。我将image.php(验证码图像文件)放在我的默认主页所在的视图文件夹中但它无论如何都不起作用。

image.php

  <?php
  session_start();
  function random($length){
                $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
                $str = "";
                $size = strlen($chars);

                for($i=0; $i<$length; $i++){
                        $str .= $chars[rand(0, $size-1)];
                }
                return $str;
        }

        $cap = random(7);
        $_SESSION['real'] = $cap;

        $image = imagecreate(120,35);
        $background = imagecolorallocate($image, rand(30, 140),rand(30, 140),rand(30, 140));
        $foreground = imagecolorallocate($image,255,255,255);

        for($i=0; $i<30; $i++){
                $x1 = rand(1,100);
                $x2 = rand(1,100);
                $y1 = rand(1,100);
                $y2 = rand(1,100);

                imageline($image, $x1, $y1, $x2, $y2, $foreground);
        }

        //echo __PATH.'/view/account.php';

        /*if(is_readable(__PATH.'/view/GenBasB.ttf')){
            //echo 'Font file is readable';
        }else{
            //echo 'font file not readable';
        }*/


        //imagestring($image, 10,15,10, $cap, $foreground);
        imagettftext($image, 20, 0, 8, 23, $foreground, 'view/GenBasBI.ttf',$cap);
        header("Content-type: image/jpeg");
        imagejpeg($image);


        ?>

的index.php 的                                    主页         

    <link rel="stylesheet" href="public/css/common.css" >
    <link rel="stylesheet" href="public/css/home.css" >


    <script src='public/js/jquery-1.10.2.min.js'></script>
    <script src='public/js/lib.js'></script>



    </head>
        <body >

            <div class="main_wrapper">
                    <div class="header">
                    </div>  <!-- header DIV ends here -->
                    <div id="nav_wrapper" >
                            <div id="nav_menu">
                                    <ul>
                                            <li><a id="nav_link" href="/p1">Home</a></li>
                                            <li><a id="nav_link" href="#">How It Works</a></li>
                                            <li><a id="nav_link" href="directory.php">Directory</a></li>
                                            <li><a id="nav_link" href="testimonials.php">Testimonials</a></li>
                                            <li><a id="nav_link" href="contact.php">Contact</a></li>
                                            <li><a id="nav_link" href="faq.php">FAQ</a></li>
                                    </ul>
                            </div>  <!-- nav menu DIV ends here -->
                    </div>  <!-- nav wrapper DIV ends here -->
                    <div class="middle_wrapper">

                            <div class="middle_panel" id="myDiv">   
                                    <div class="advert_banner">             
                                            <a href="#" >
                                                    <img src="public/images/banner444.gif"   />
                                            </a>
                                    </div>  <!-- advert banner DIV ends here -->
                                    <div class="login_box">
                                            <div id="members_login">Member's Login</div>
                                            <form method="post" action="auth_login">
                                                            <p>Not a member yet? <a href="signup.php" class="sign-up">Sign Up!</a></p><br />
                                                            <div class="form_controls">
                                                                    <label class="field_label">Username:</label>
                                                                    <div class="field_input">
                                                                            <input type="text" name="username" autocomplete="off" />
                                                                    </div>
                                                            </div>

                                                            <div class="form_controls">                     
                                                                    <label class="field_label">Password:</label>
                                                                    <div class="field_input">
                                                                            <input type="password" name="password" autocomplete="off" />
                                                                    </div>
                                                            </div>

                                                            <div class="form_controls">
                                                                    <label class="field_label">Captha Code:</label>
                                                                    <div class="field_input">
                                                                            <input type="text" name="code" autocomplete="off" /> 
                                                                            <img src="view/image.php" />


                                                                    </div>
                                                            </div>
                                                            <img src="view/code.php"></img>
                                                            <br />
                                                            <div class="form_bottom">
                                                                    <input type="submit" value="Login" />
                                                                    <p><a href="#">Forgot Password? Click here</a></p>
                                                            </div>
                                                    </form>
                                    </div>  <!-- login box DIV ends here --> 


              </div>    <!-- middle panel DIV ends here -->         
    </div>  <!-- middle wrapper DIV ends here -->
                    <div class="right_panel" id="myDiv"> 

                            <div class="right_advert1">
                            </div>
                            <div class="right_advert2"> 
                            </div>
                            <div class="right_advert3">
                            </div>
                            <div class="right_advert4">
                            </div>
                            <div class="right_advert5">
                            </div>
                            <div class="right advert6">
                            </div>
                            <div class="right_advert7">
                            </div>
                            <div class="right_advert8">
                            </div>
                            <div class="right_advert9">
                            </div>
                            <div class="right_advert10">
                            </div>  

                    </div>  <!-- right panel DIV ends here -->

            <div class="footer">

                    <ul>
                            <li><a id="nav_link" href="/p1">Home</a></li>
                            <li><a id="nav_link" href="#">About</a></li>
                            <li><a id="nav_link" href="directory.php">Directory</a></li>
                            <li><a id="nav_link" href="testimonials.php">Testimonials</a></li>
                            <li><a id="nav_link" href="contact.php">Contact</a></li>
                            <li><a id="nav_link" href="agreement.php">Agreement</a></li>
                    </ul>

                    <br /><br /><br /><br />        
                    <p> 2013 XYZ Company, All Rights Reserved.</p>
            </div>

            </div>  <!-- main wrapper DIV ends here -->

    </body>
    </html>

在这个index.php页面上有一个登录表单,我想使用验证码。现在我将index.php和image.php文件放在VIEW文件夹中。但是仍然没有显示图像,但是无效的图像符号就像错误一样。

0 个答案:

没有答案
相关问题