Professional Documents
Culture Documents
Simple PHP Login Code Example
Simple PHP Login Code Example
in Biow's world..
mundane musings and such..
SEA RCH
Search
SP O NSO R E D LI NK S
11
A u g Th u 2 01 1
While tasked to code my very first php program, I did some googling.. who codes from scratch these days?.. but while googling, the sample codes were mind boggling.. me, the google-queen I am, will not fail.. after much soul code-searching, I found the forum posting here easiest to follow.. I copied the codes over to preserve the knowledge in case the forum can't be assessed any longer.. what gibberish mess right? ahh.. to be honest, I find joy writing codes.. as long as there is absolutely NO deadline.. ahh, what joy to see these gibberish turned into some webpages that can be responded to.. it's fun.. honest!
< ? / /R e p l a c et h ev a r i a b l ev a l u e sb e l o w / /w i t hy o u rs p e c i f i cd a t a b a s ei n f o r m a t i o n . $ h o s t=" l o c a l h o s t " ; $ u s e r=" U s e r N a m e " ; $ p a s s=" P a s s w o r d " ; $ d b=" d b N a m e " ; / /T h i sp a r ts e t su pt h ec o n n e c t i o nt ot h e / /d a t a b a s e( s oy o ud o n ' tn e e dt or e o p e nt h ec o n n e c t i o n / /a g a i no nt h es a m ep a g e ) . $ m s=m y s q l _ p c o n n e c t ( $ h o s t ,$ u s e r ,$ p a s s ) ; i f(! $ m s) { e c h o" E r r o rc o n n e c t i n gt od a t a b a s e . \ n " ; } / /T h e ny o un e e dt om a k es u r et h ed a t a b a s ey o uw a n t / /i ss e l e c t e d . m y s q l _ s e l e c t _ d b ( $ d b ) ; ? >
A ll say cheese printed matter biow's tutorial chomp-chomp craft, scrapbook, PS yours truly ken & wenn dino keno korean drama value creation (soka) road less travelled ties that bind tete-a-tete nen-nen (bfg) techie-geekie wenn education BFF kindred spirit
TA G S art_n_craft cny comic cut-off cut-off_jc cut-off_psle cut-off_uni education family flash
< ? p h p
www.post1.net/biow/entry/simple_php_login_code_example
1/4
7/4/13
/ / I n p u tv a i l d a t i o na n dt h ed b a s ec o d e i f($ _ G E T [ " o p " ]= =" r e g ") { $ b I n p u t F l a g=f a l s e ; f o r e a c h($ _ P O S Ta s$ f i e l d) { i f( $ f i e l d= =" " ) { $ b I n p u t F l a g=f a l s e ; } e l s e { $ b I n p u t F l a g=t r u e ; } } / /I fw eh a dp r o b l e m sw i t ht h ei n p u t ,e x i tw i t he r r o r i f( $ b I n p u t F l a g= =f a l s e ) { d i e (" P r o b l e mw i t hy o u rr e g i s t r a t i o ni n f o ." . " P l e a s eg ob a c ka n dt r ya g a i n . " ) ; } / /F i e l d sa r ec l e a r ,a d du s e rt od a t a b a s e / / S e t u pq u e r y $ q=" I N S E R TI N T O` d b U s e r s `( ` u s e r n a m e ` , ` p a s s w o r d ` , ` e m a i l ` )" . " V A L U E S( ' " . $ _ P O S T [ " u s e r n a m e " ] . " ' ," . " P A S S W O R D ( ' " . $ _ P O S T [ " p a s s w o r d " ] . " ' ) ," . " ' " . $ _ P O S T [ " e m a i l " ] . " ' ) " ; / / R u nq u e r y $ r=m y s q l _ q u e r y ( $ q ) ; / /M a k es u r eq u e r yi n s e r t e du s e rs u c c e s s f u l l y i f(! m y s q l _ i n s e r t _ i d ( )) { d i e ( " E r r o r :U s e rn o ta d d e dt od a t a b a s e . " ) ; } e l s e { / /R e d i r e c tt ot h a n ky o up a g e . H e a d e r ( " L o c a t i o n :r e g i s t e r . p h p ? o p = t h a n k s " ) ; } }/ /e n di f
/ / T h et h a n ky o up a g e e l s e i f($ _ G E T [ " o p " ]= =" t h a n k s ") { e c h o" < h 2 > T h a n k sf o rr e g i s t e r i n g ! < / h 2 > " ; } / / T h ew e bf o r mf o ri n p u ta b i l i t y e l s e { e c h o" < f o r ma c t i o n = \ " ? o p = r e g \ "m e t h o d = \ " P O S T \ " > \ n " ; e c h o" U s e r n a m e :< i n p u tn a m e = \ " u s e r n a m e \ "M A X L E N G T H = \ " 1 6 \ " > < b r/ > \ n " ; e c h o" P a s s w o r d :< i n p u tt y p e = \ " p a s s w o r d \ "n a m e = \ " p a s s w o r d \ "M A X L E N G T H = \ " 1 6 \ " > < b r/ > \ n " ; e c h o" E m a i lA d d r e s s :< i n p u tn a m e = \ " e m a i l \ "M A X L E N G T H = \ " 2 5 \ " > < b r/ > \ n " ; e c h o" < i n p u tt y p e = \ " s u b m i t \ " > \ n " ; e c h o" < / f o r m > \ n " ; } / /E O F ? >
P O W ER ED B Y R O L L ER
< ? p h p s e s s i o n _ s t a r t ( ) ; / /d B a s ef i l e i n c l u d e" d b C o n f i g . p h p " ; i f( $ _ G E T [ " o p " ]= =" l o g i n " ) { i f( ! $ _ P O S T [ " u s e r n a m e " ]| |! $ _ P O S T [ " p a s s w o r d " ] ) { d i e ( " Y o un e e dt op r o v i d eau s e r n a m ea n dp a s s w o r d . " ) ;
www.post1.net/biow/entry/simple_php_login_code_example
2/4
7/4/13
}
/ /C r e a t eq u e r y $ q=" S E L E C T*F R O M` d b U s e r s `" . " W H E R E` u s e r n a m e ` = ' " . $ _ P O S T [ " u s e r n a m e " ] . " '" . " A N D` p a s s w o r d ` = P A S S W O R D ( ' " . $ _ P O S T [ " p a s s w o r d " ] . " ' )" . " L I M I T1 " ; / /R u nq u e r y $ r=m y s q l _ q u e r y ( $ q ) ; i f($ o b j=@ m y s q l _ f e t c h _ o b j e c t ( $ r )) { / /L o g i ng o o d ,c r e a t es e s s i o nv a r i a b l e s $ _ S E S S I O N [ " v a l i d _ i d " ]=$ o b j > i d ; $ _ S E S S I O N [ " v a l i d _ u s e r " ]=$ _ P O S T [ " u s e r n a m e " ] ; $ _ S E S S I O N [ " v a l i d _ t i m e " ]=t i m e ( ) ; / /R e d i r e c tt om e m b e rp a g e H e a d e r ( " L o c a t i o n :m e m b e r s . p h p " ) ; } e l s e { / /L o g i nn o ts u c c e s s f u l d i e ( " S o r r y ,c o u l dn o tl o gy o ui n .W r o n gl o g i ni n f o r m a t i o n . " ) ; } } e l s e { / / I fa l lw e n tr i g h tt h eW e bf o r ma p p e a r sa n du s e r sc a nl o gi n e c h o" < f o r ma c t i o n = \ " ? o p = l o g i n \ "m e t h o d = \ " P O S T \ " > " ; e c h o" U s e r n a m e :< i n p u tn a m e = \ " u s e r n a m e \ "s i z e = \ " 1 5 \ " > < b r/ > " ; e c h o" P a s s w o r d :< i n p u tt y p e = \ " p a s s w o r d \ "n a m e = \ " p a s s w o r d \ "s i z e = \ " 8 \ " > < b r/ > " ; e c h o" < i n p u tt y p e = \ " s u b m i t \ "v a l u e = \ " L o g i n \ " > " ; e c h o" < / f o r m > " ; } ? >
< ? p h p s e s s i o n _ s t a r t ( ) ; i f( ! $ _ S E S S I O N [ " v a l i d _ u s e r " ] ) { / /U s e rn o tl o g g e di n ,r e d i r e c tt ol o g i np a g e H e a d e r ( " L o c a t i o n :l o g i n . p h p " ) ; } / /M e m b e ro n l yc o n t e n t / /. . . / /. . . / /. . . / /D i s p l a yM e m b e ri n f o r m a t i o n e c h o" < p > U s e rI D :".$ _ S E S S I O N [ " v a l i d _ i d " ] ; e c h o" < p > U s e r n a m e :".$ _ S E S S I O N [ " v a l i d _ u s e r " ] ; e c h o" < p > L o g g e di n :".d a t e ( " m / d / Y " ,$ _ S E S S I O N [ " v a l i d _ t i m e " ] ) ; / /D i s p l a yl o g o u tl i n k e c h o" < p > < ah r e f = \ " l o g o u t . p h p \ " > C l i c kh e r et ol o g o u t ! < / a > < / p > " ; ? >
www.post1.net/biow/entry/simple_php_login_code_example
3/4
7/4/13
Comments:
Post a Comment:
Comments are closed for this entry. RIP | Main | Korean Drama: City...
Most popular blog postings in Biow's world: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 2010 O-Levels cut off point to JC (Junior College) in Singapore Sengkang Swimming Complex Recipe: Honey Vanilla Pound Cake Recipe by Ina Garten of Barefoot Contessa Fisheye effect with Photoshop CS 3 Digital photography tutorial for Nikon D40 DSLR Canon DSLR Tutorial Guide for Beginners Watch Korean Dramas online for FREE.. Feeding your drama addiction.. more links to watch korean dramas online free with subs Korean Drama: The Legend (Tae Wang Sa Shin Gi) by Bae Yong Joon Episode Guide resignation letter for less than tender notice sample
Featured articles in Biow's world: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. Singapore Maths P1 Worksheet Online Generator - Problem Sums Singapore Maths P2 Worksheet Canon DSLR Tutorial Guide for Beginners Cake Decoration 101 - How to cream / frost a cake Cake Decoration 101 - Shell Piping Freezing Expressed Breastmilk (EBM) in 3 steps Another way to freeze Expressed Breastmilk (EBM) Storing of Expressed Breastmilk (EBM) How Breastfeeding Benefits Add Up Do not use glass bottle to freeze your precious breastmilk
College Education
Metering
Meter
Locations
Education
Database
Login Code
www.post1.net/biow/entry/simple_php_login_code_example
4/4