如何在同一页面上提交的表单中使用securimage captcha?

时间:2013-10-22 20:42:57

标签: php captcha

我想在我的drupal网站上使用securimage captcha,

我有一份注册表格,我在同一页面上提交该表格。

Securimage配置文档说(here)在表单处理器的第一行使用session_start()。

我在同一页面上同时拥有表单和表单处理器,那么我应该在哪里编写session_start()?

这是我的代码

<form id="user_form" action="" method="post">
                <div class="form">
                    <?php if (isset($errors) && count($errors)>0) : ?>
                        <ul class="error-list">
                            <?php foreach ($errors as $e) : ?>
                                <li><?php echo $e; ?></li>
                            <?php endforeach; ?>
                        </ul>
                    <?php endif; ?>

                    <div class="form-section">
                        <div class="col">
                          <div class="row">                                
                                <label class="two-rows">Select your<br />account type <span>*</span></label>
                                <select name="uf_user_type" style="width:173px;" class="required">
                                    <option value="">None Selected</option>
                                    <option value="<?php print JOB_SEEKER_ROLE; ?>">Job Seeker</option>
                                    <option value="<?php print MASTER_EMPLOYER_ROLE; ?>">Employer</option>
                                </select>
                                <div class="cl">&nbsp;</div>
                                <em class="status"></em>
                            </div>
                            <div class="row">                                
                                <label>First Name <span>*</span></label>
                                <input type="text" class="field required" name="uf_first_name"  />
                                <div class="cl">&nbsp;</div>
                                <em class="status"></em>
                            </div>

                            <div class="row">                                
                                <label>Last Name <span>*</span></label>
                                <input type="text" class="field required" name="uf_last_name" />
                                <div class="cl">&nbsp;</div>
                                <em class="status"></em>
                            </div>

                            <div class="row">                                
                                <label>Email <span>*</span></label>
                                <input type="text" class="field required email-field" name="uf_mail" />
                                <div class="cl">&nbsp;</div>
                                <em class="status"></em>
                            </div>
                            <div class="row">                                
                                <div class="cl">&nbsp;</div>
                            </div>
                            <div class="row">
                                <label class="two-rows">Image <span>*</span></label>
                                <img id="captcha" src="/sites/all/themes/jobnow/site/securimage/securimage_show.php" alt="CAPTCHA Image" height="45" width="160" style="border:1px solid #b9b9b9"/>&nbsp;
                                <a href="#" onclick="document.getElementById('captcha').src = '/sites/all/themes/jobnow/site/securimage/securimage_show.php?' + Math.random(); return false">
                                    <img src="/sites/all/themes/jobnow/site/securimage/images/refresh.png" height="30" width="30" alt="Reload Image" onclick="this.blur()" align="bottom" border="0">
                                </a>
                            </div>
                        </div>

                        <div class="col right-col">
                            <div class="row">                                
                                <label class="two-rows">How did you <br />hear about us? <span>*</span></label>
                                <select name="uf_hear_about_us" style="width:173px;" class="required">
                                    <option value="">None Selected</option>
                                    <option>Colleague/Friend</option>
                                    <option>Search Engine</option>
                                    <option>LinkedIn</option>
                                    <option>Twitter</option>
                                    <option>Facebook</option>
                                    <option>Advertisement</option>
                                    <option>In The News</option>
                                    <option>Trade Show/Organization</option>
                                    <option>Other</option>
                                </select>
                                <div class="cl">&nbsp;</div>
                                <em class="status"></em>
                            </div>
                            <div class="row">
                                <p class="hint"><?php echo bfstring('hint_register_password'); ?></p>
                                <label>Password <span>*</span></label>
                                <input type="password" class="field required" id="pass1" name="uf_password" />
                                <div class="cl">&nbsp;</div>
                                <em class="status"></em>
                            </div>

                            <div class="row">
                                <label class="two-rows">Confirm <br />Password <span>*</span></label>
                                <input type="password" class="field required" id="pass2" name="uf_password2" />
                                <div class="cl">&nbsp;</div>
                                <em class="status"></em>
                            </div>
                            <div class="row">                                
                                <label class="labelBlack">
                                    <input type="checkbox" class="check required" name="uf_terms"  value="1" <?php if(isset($_POST['uf_terms']) && $_POST['uf_terms'] == 1) print 'checked'; ?> />
                                </label>
                                <p>I accept the <a href="<?php echo url('legal'); ?>"target="_blank">Terms of Service.</a></p>                            
                                <div class="cl">&nbsp;</div>
                            </div>
                            <div class="row">                                
                                <div class="cl">&nbsp;</div>
                            </div>
                            <div class="row">
                                <label class="two-rows">What code is<br />in the image?<span>*</span></label>
                                <input type="text" class="field required" name="captcha_code" size="10" maxlength="6" />
                                <div class="cl">&nbsp;</div>
                                <em class="status"></em>
                            </div>
                        </div>
                            <div class="cl">&nbsp;</div>
                    </div>
                <div>


                              </div>
                    <div class="form-actions">
                        <span class="required-info"><strong>*</strong> required</span>
                        <input type="submit" class="form-submit" value="Create Account" />
                        <a href="javascript:history.go(-1);">Cancel</a>
                        <div class="cl">&nbsp;</div>
                    </div>
                </div>
            </form>


     if ($_SERVER['REQUEST_METHOD'] == 'POST')
            {

                    $securimage = new Securimage();
                    $isSecurImageValid=$securimage->check($_POST['captcha_code']) != false;

                if ($validator->validateRules($_POST) && $isSecurImageValid)
                {   
                    $new_user = new stdClass();
                    $new_user->roles = array();
                    $username_base =strtolower(preg_replace('~(.*)\@.*~', '$1', site_rgpc($_POST['uf_mail'])));
                    $usernames = array();
                  }
              else
            {
                $errors = $validator->getErrors();
                    if(!$isSecurImageValid)
                        $errors[]="The Security Code wasn't entered correctly.";
            }

当我在我的网站上集成此代码时,它表示您的验证码对于每次尝试都是错误的。

我没有得到什么问题?

相同的代码在我的另一个类似网站上没有session_start()的情况下工作。

请帮帮我

0 个答案:

没有答案