The previous article analyzes the data streams between authpuppy under wifidog. In this article, I will introduce how to write a simple advertising router.
After the above analysis, it is not difficult to see that it is very simple to implement an advertising router.
Because I am not familiar with the symfony framework, the following sample code uses the Phalcon framework for writing (only for demonstration)
<? Phpnamespace controllers; Class interfacecontroller extends \ Phalcon \ MVC \ controller {public function initialize () {} public function indexaction () {} public function loginaction () {if ($ this-> request-> isget () & null = $ this-> request-> getquery ('advs ')) {$ strdebug = var_export ($ _ server, true); $ this-> View-> setvar ('frefreshtime', 10 ); // The advertising time is 10 seconds. $ this-> View-> setvar ('url', $ this-> request-> getserver ('Request _ URI '). '& ADVs = ADVs'); $ this-> View-> pick ('interface/ADVs '); // here, the advertisement is displayed.} else {$ this-> View-> disable (); $ strtoken = sha1 (RAND (). time (); $ this-> persistent-> set ('redirecturl', $ this-> request-> getquery ('url ')); $ this-> response-> redirect ('HTTP ://'. $ this-> request-> get ('gw _ address '). ':'. $ this-> request-> get ('gw _ port '). '/wifidog/auth? Token = '. $ strtoken, true) ;}} public function logoutaction () {echo 'auth: 0';} public function portalaction () {// jump to $ this-> View-> disable (); If (null! = $ Strurl = $ this-> persistent-> get ('redirecturl') {$ this-> response-> redirect ($ strurl, true );} else {$ this-> response-> redirect ('HTTP: // blog.csdn.net/qzfzz', true) ;}} public function pingaction () {echo 'pong ';} public function msgaction () {} public function authaction () {echo 'auth: 1 ';}}
View
<! -- ADVs. phtml --> <! Doctype HTML <HTML>
After the above development, a simple advertising router is completed.
Advertisement router development (ii) practices