The php anthology 2nd edition 2007 - phần 7 pdf

55 324 0
The php anthology 2nd edition 2007 - phần 7 pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Access Control Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com $sign_pass = $this->cfg['signup_table']['col_password']; $sign_email = $this->cfg['signup_table']['col_email']; $sign_first = $this->cfg['signup_table']['col_name_first']; $sign_last = $this->cfg['signup_table']['col_name_last']; $sign_sig = $this->cfg['signup_table']['col_signature']; $sign_code = $this->cfg['signup_table']['col_code']; try { $sql = "SELECT * FROM " $sign_table " WHERE " $sign_code "=:confirmCode"; $stmt = $this->db->prepare($sql); $stmt->bindParam(':confirmCode', $confirmCode); $stmt->execute(); $row = $stmt->fetchAll(); } catch (PDOException $e) { throw new SignUpDatabaseException('Database error when' ' inserting user info: '.$e->getMessage()); } Again, we assign configuration settings to local variables to improve the script’s readability First, the confirm method selects from the signup table all records that have a value in the confirm_code column that matches the $confirmCode value If the number of records returned is anything other than 1, a problem has occurred and a SignUpConfirmationException exception is thrown: Signup.class.php (excerpt) if (count($row) != 1) { throw new SignUpConfirmationException(count($row) ' records found for confirmation code: ' $confirmCode ); } If only one matching record is found, the method can continue to process the con­ firmation: 307 308 The PHP Anthology Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Signup.class.php (excerpt) try { // Copy the data from Signup to User table $sql = "INSERT INTO " $user_table " ( " $user_login ", " $user_pass ", " $user_email ", " $user_first ", " $user_last ", " $user_sig ") VALUES ( :login, :pass, :email, :firstname, :lastname, :sign )"; $stmt = $this->db->prepare($sql); $stmt->bindParam(':login',$row[0][$sign_login]); $stmt->bindParam(':pass',$row[0][$sign_pass]); $stmt->bindParam(':email',$row[0][$sign_email]); $stmt->bindParam(':firstname',$row[0][$sign_first]); $stmt->bindParam(':lastname',$row[0][$sign_last]); $stmt->bindParam(':sign',$row[0][$sign_sig]); $stmt->execute(); $result = $stmt->fetch(); // Delete row from signup table $sql = "DELETE FROM " $sign_table " WHERE " $sign_id "= :id"; $stmt = $this->db->prepare($sql); $stmt->bindParam(':id', $row[0][$sign_id]); $stmt->execute(); } catch (PDOException $e) { throw new SignUpDatabaseException('Database error when' ' inserting user info: '.$e->getMessage()); } } } If an account is successfully confirmed, the record is copied to the user table, and the old record is deleted from the signup table Thus the confirmation process, the user’s registration, and our SignUp class, is complete! The Signup Page Now that our SignUp class is done, we need a web page from which to display the registration form and run the process Access Control Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com The first step is to include the classes we’ll use: signup.php (excerpt)

Ngày đăng: 13/08/2014, 09:20

Từ khóa liên quan

Mục lục

  • The PHP Anthology

    • Table of Contents

    • Preface

      • Who Should Read this Book?

      • What’s Covered in this Book?

      • Running the Code Examples

      • The Book’s Web Site

        • The Code Archive

        • Updates and Errata

        • The SitePoint Forums

        • The SitePoint Newsletters

        • Your Feedback

        • Conventions Used in this Book

          • Code Samples

          • Tips, Notes, and Warnings

          • Introduction

            • Where do I get help?

              • Solution

                • RTFM: Read the Fine Manual

                  • I. Getting Started and II. Installation and Configuration

                  • III. Language Reference

                  • IV. Security

                  • V. Features

                  • VI. Function Reference

                    • PHP Extensions

                    • User Comments

                    • Other Resources

                    • What is OOP?

                      • Solution

                        • Classes Explained

                          • Encapsulation and Visibility

                          • Constructors and Destructors

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan