PHP login proxy

Source: Internet
Author: User
PHP login proxy
#### Proxy mode * composition * abstract role: business method implemented by the real role of the interface or abstract class Life * proxy role: implements the abstract role, which is a real role proxy * real role: implement the abstract role and define the business logic to be implemented by the real role #### implement the Mysql connection class "/*** Created by PhpStorm. * User: gewenrui * Date: 16/3/13 * Time: */namespace db; // php allows you to store the constant interface IConnectInfo {// server name const HOST = "localhost"; // User name const USERNAME = "root"; // PASSWORD const PASSWORD = ""; // database name 444444444444444444444 const DBNAME = "proxylog"; public function doConnect ();} class UniversalConnect implements IConnectInfo {// implements the scope resolution operator to access the connection value. // the processing speed advantage of static variables provides private visibility to provide encapsulation of private static $ server = IConnectInfo :: HOST; private static $ currentDB = IConnectInfo: DBNAME; private static $ username = IConnectInfo: USERNAME; private static $ password = IConnectInfo: PASSWORD; private static $ hookup; public function doConnect () {// connect to the database self ::$ hookup = mysqli_connect (self ::$ server, self ::$ username, self ::$ password, self :: $ currentDB); if (self: $ hookup) {echo "Successfucl connection to MYSQL "."
";} Else if (mysqli_connect_error (self: $ hookup) {echo "". mysqli_connect_error ();} return self: $ hookup ;}} "###### create a table" class CreateTable {// set the table name private $ tableMaster = "proxyLog"; private $ hookup; public function _ construct () {$ this-> tableMaster = "proxyLog"; $ this-> hookup = UniversalConnect: doConnect (); $ drop = "drop table if exits $ this-> tableMaster "."
"; // Echo $ drop; if ($ this-> hookup-> query ($ drop) = true) {printf (" Old table % s has been dropped "."
", $ This-> tableMaster);} $ SQL =" CREATE TABLE $ this-> tableMaster (uname VARCHAR (15), pw VARCHAR (120 ))"; // echo $ SQL; if ($ this-> hookup-> query ($ SQL) = true) {echo "Table {$ this-> tableMaster} has been created successful" ;}$ this-> hookup-> close ();}} "###### add data to the table" class HashRegister {public function _ construct () {$ this-> tableMaster = "proxyLog "; $ this-> hookup = UniversalConnect: doConnect (); $ username = $ this-> hookup-> real_escape_string (trim ($ _ POST ['uname']); $ password = $ this-> hookup-> real_escape_string (trim ($ _ POST ['pw ']); $ SQL = "INSERT INTO $ this-> tableMaster (uname, pw) VALUES ('$ username', md5 (' $ password') "; echo $ SQL; if ($ this-> hookup-> query ($ SQL )) {echo "registeration conpleted";} else if ($ result = $ this-> hookup-> query ($ SQL) = false) {printf ("Invalid query: % s while query % s "); exit (); $ this-> hookup-> close () ;}}" #### implement user login in proxy mode" TableMaster = "proxyLog"; $ this-> hookup = \ db \ UniversalConnect: doConnect (); $ this-> un = $ this-> hookup-> real_escape_string (trim ($ _ POST ['uname']); $ this-> pw = $ this-> hookup-> real_escape_string (trim ($ _ POST ['pw ']); // proxy mode $ this-> getIface ($ this-> Proxy = new proxy ();} public function getIface (ISubject $ proxy) {$ proxy-> login ($ this-> un, $ this-> pw) ;}// Proxy class proxy implements ISubject {private $ tableMaster; private $ hookup; private $ logGood; private $ realSubject; public function login ($ uNow, $ pwNow) {$ uname = $ uNow; $ pw = md5 ($ pwNow ); $ this-> logGood = false; $ this-> tableMaster = "proxyLog"; $ this-> hookup = \ db \ UniversalConnect: doConnect (); $ SQL = "SELECT pw from $ this-> tableMaster WHERE uname = '$ uname'"; if ($ result = $ this-> hookup-> query ($ SQL )) {$ row = $ result-> fetch_array (MYSQLI_ASSOC); echo $ pw; if ($ row ['pw '] = $ pw) {$ this-> logGood = true;} $ result-> close ();} else if ($ result = $ this-> hookup-> query ($ SQL) === false) {printf ("failed % s", $ this-> hookup-> error); exit ();} $ this-> hookup-> close (); if ($ this-> logGood) {// execute the request method $ this-> request ();} else {echo "username and/or password not on record" ;}} public function request () {$ this-> realSubject = new RealSubject (); $ this-> realSubject-> request () ;}} class RealSubject implements ISubject {public function request () {$ practice = < Data
  1. Fuck u silly B
REQUEST; echo $ practice ;}}$ data = new Client ();"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.