Your SlideShare is downloading. ×
0
04 Html Form Get Post Login System
04 Html Form Get Post Login System
04 Html Form Get Post Login System
04 Html Form Get Post Login System
04 Html Form Get Post Login System
04 Html Form Get Post Login System
04 Html Form Get Post Login System
04 Html Form Get Post Login System
04 Html Form Get Post Login System
04 Html Form Get Post Login System
04 Html Form Get Post Login System
04 Html Form Get Post Login System
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

04 Html Form Get Post Login System

2,620

Published on

HTML form handing with PHP and POST varibales

HTML form handing with PHP and POST varibales

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,620
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. PHP Day 4 Geshan Manandhar Developer, Young Innovations Private Limited www.geshanmanandhar.com http://www.php.net
  • 2. HTML Forms <ul><li><form name=“form1” method=“ post ” action=“process_form.php”> …. </form> </li></ul><ul><li><input type=“text” name=“user_name”> </li></ul><ul><li><input type=&quot;password&quot; name=&quot;pass_word“> </li></ul><ul><li><input type=&quot;submit&quot; name=&quot;submit_form&quot; value=&quot;Submit&quot; /> </li></ul><ul><li>For display formatted forms use tables. </li></ul><ul><li>For more see http://www.w3schools.com/html/html_forms.asp </li></ul>
  • 3. Require and Include <ul><li>require(‘path/to/file_name.php’) </li></ul><ul><li>include(‘path/to/file_name.php’) </li></ul><ul><ul><li>Difference is require will throw a Fatal error is file required is not found include will just throw a warning. </li></ul></ul><ul><li>require_once(‘path/to/file_name.php’); </li></ul><ul><li>include_once(‘path/to/file_name.php’); </li></ul><ul><ul><li>To require or include a file just once. </li></ul></ul>
  • 4. Session Management <ul><li>session_start — Initialize session data </li></ul><ul><li>$_SESSION[‘index’] = “value”; </li></ul><ul><ul><li>$_SESSION[‘user_name’] = $user_name; </li></ul></ul><ul><li>session_destroy — Destroys all data registered to a session </li></ul>
  • 5. A simple login interface
  • 6. Login Check function <ul><li>Getting Variables and starting session. </li></ul><ul><li><?php </li></ul><ul><li>session_start(); </li></ul><ul><li>$user_name = $_POST[‘user_name’]; </li></ul><ul><li>$pass_word = $_POST[‘pass_word’]; </li></ul>
  • 7. Login Check function <ul><li>The Function definition </li></ul><ul><li>function check_login($user_name, $pass_word){ </li></ul><ul><li>if(($user_name==&quot;admin&quot;) && ($pass_word === &quot;test&quot;)) </li></ul><ul><li>{ </li></ul><ul><li>//set session </li></ul><ul><li>$_SESSION['user_name'] = $user_name; </li></ul><ul><li>$_SESSION['user_logged_in'] = true; </li></ul><ul><li>return 1; </li></ul><ul><li>} </li></ul><ul><li>else{ </li></ul><ul><li>return 0; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  • 8. Login check function <ul><li>Function call and process </li></ul><ul><li>$user_ok = check_login($user_name, $pass_word); //called from check_login_function.php </li></ul><ul><li>if($user_ok){ </li></ul><ul><li>header(&quot;Location: logged_in.php&quot;); /* Redirect browser */ </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li>header(&quot;Location: not_logged_in.php&quot;); </li></ul><ul><li>} </li></ul><ul><li>?> </li></ul>
  • 9. Either you login or are not logged in
  • 10. Session to authenticate users <ul><li>Address security issues. </li></ul><ul><li>Put content that should be seen by logged in users or even by user type. </li></ul><ul><li>User module and session management is essential to almost every system. </li></ul>
  • 11. Questions
  • 12. Let’s start practice <ul><li>Build your own login system with upto 3 user name and password combination with user of array, refer to code of Day04 . </li></ul><ul><li>Among the 3 one should be of type admin and remaining two of type user. </li></ul><ul><li>The logged in page should not be accessible directly after typing full URL/address in the address bar. </li></ul>

×