• We just launched and are currently in beta. Join us as we build and grow the community.

OOP CRUD MVC Web App With PDO Using Core PHP

Taker

Humor Commander
T Rep
0
0
0
Rep
0
T Vouches
0
0
0
Vouches
0
Posts
34
Likes
123
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
This is a simple PHP web application developed using OOP Pattern, PDO, and Core PHP. This project will help you learn how to develop a web application with MVC (Model-View-Controller). For those who are not familiar in MVC, the MVC (Model-View-Controller) is an application/software design pattern comprised of three interconnected parts which are the model, view, and controller.

Talking about the web application, this has a registration page which the user can create their new account, and also it has a secure login feature. The web application is a kind of the application of a post which user can create, edit, read, and delete posts. The delete and edit post-action buttons are only visible to users who created the post. The application is composed of 3 Controllers which are the Pages, Posts, and Users. The Pages Controller handles the public pages, Posts Controllers handles the posts side, and Users Controllers handles the users' login and registrations.

Controllers:

Pages.php



  1. <?php
  2. class

    Pages extends

    Controller {
  3. public

    function

    __construct(

    )

    {

  4. }

  5. public

    function

    index(

    )

    {
  6. if

    (

    isLoggedIn(

    )

    )

    {
  7. redirect(

    'posts'

    )

    ;
  8. }
  9. $data

    =

    [
  10. 'title'

    =>

    'SharePosts'

    ,
  11. 'description'

    =>

    'Simple social network built on the Emmizy MVC framework'

    ,
  12. 'info'

    =>

    'You can contact me with the following details below if you like my program and willing to offer me a contract and work on your project'

    ,
  13. 'name'

    =>

    'Omonzebaguan Emmanuel'

    ,
  14. 'location'

    =>

    'Nigeria, Edo State'

    ,
  15. 'contact'

    =>

    '+2348147534847'

    ,
  16. 'mail'

    =>

    '[email protected]'
  17. ]

    ;

  18. $this

    ->

    view

    (

    'pages/index'

    ,

    $data

    )

    ;
  19. }

  20. public

    function

    about(

    )

    {
  21. $data

    =

    [
  22. 'title'

    =>

    'About Us'

    ,
  23. 'description'

    =>

    'App to share posts with other users'
  24. ]

    ;

  25. $this

    ->

    view

    (

    'pages/about'

    ,

    $data

    )

    ;
  26. }

  27. public

    function

    contact(

    )

    {
  28. $data

    =

    [
  29. 'title'

    =>

    'Contact Us'

    ,
  30. 'description'

    =>

    'You can contact us through this medium'

    ,
  31. 'info'

    =>

    'You can contact me with the following details below if you like my program and willing to offer me a contract and work on your project'

    ,
  32. 'name'

    =>

    'Omonzebaguan Emmanuel'

    ,
  33. 'location'

    =>

    'Nigeria, Edo State'

    ,
  34. 'contact'

    =>

    '+2348147534847'

    ,
  35. 'mail'

    =>

    '[email protected]'
  36. ]

    ;

  37. $this

    ->

    view

    (

    'pages/contact'

    ,

    $data

    )

    ;
  38. }
  39. }

Posts.php



  1. <?php
  2. class

    Posts extends

    Controller{

  3. public

    function

    __construct(

    )
  4. {
  5. if

    (

    !

    isLoggedIn(

    )

    )

    {
  6. redirect(

    'users/login'

    )

    ;
  7. }
  8. //new model instance
  9. $this

    ->

    postModel

    =

    $this

    ->

    model

    (

    'Post'

    )

    ;
  10. $this

    ->

    userModel

    =

    $this

    ->

    model

    (

    'User'

    )

    ;
  11. }

  12. public

    function

    index(

    )

    {

  13. $posts

    =

    $this

    ->

    postModel

    ->

    getPosts

    (

    )

    ;
  14. $data

    =

    [
  15. 'posts'

    =>

    $posts
  16. ]

    ;

  17. $this

    ->

    view

    (

    'posts/index'

    ,

    $data

    )

    ;
  18. }

  19. //add new post
  20. public

    function

    add(

    )

    {
  21. $_POST

    =

    filter_input_array

    (

    INPUT_POST,

    FILTER_SANITIZE_STRING)

    ;
  22. if

    (

    $_SERVER

    [

    'REQUEST_METHOD'

    ]

    ==

    'POST'

    )

    {
  23. $data

    =

    [
  24. 'title'

    =>

    trim

    (

    $_POST

    [

    'title'

    ]

    )

    ,
  25. 'body'

    =>

    trim

    (

    $_POST

    [

    'body'

    ]

    )

    ,
  26. 'user_id'

    =>

    $_SESSION

    [

    'user_id'

    ]

    ,
  27. 'title_err'

    =>

    ''

    ,
  28. 'body_err'

    =>

    ''

    ,
  29. ]

    ;

  30. if

    (

    empty

    (

    $data

    [

    'title'

    ]

    )

    )

    {
  31. $data

    [

    'title_err'

    ]

    =

    'Please enter post title'

    ;
  32. }
  33. if

    (

    empty

    (

    $data

    [

    'body'

    ]

    )

    )

    {
  34. $data

    [

    'body_err'

    ]

    =

    'Please enter the post content'

    ;
  35. }

  36. //validate error free
  37. if

    (

    empty

    (

    $data

    [

    'title_err'

    ]

    )

    &&

    empty

    (

    $data

    [

    'body_err'

    ]

    )

    )

    {
  38. if

    (

    $this

    ->

    postModel

    ->

    addPost

    (

    $data

    )

    )

    {
  39. flash(

    'post_message'

    ,

    'Your post have been added'

    )

    ;
  40. redirect(

    'posts'

    )

    ;
  41. }

    else

    {
  42. die

    (

    'something went wrong'

    )

    ;
  43. }

  44. //laod view with error
  45. }

    else

    {
  46. $this

    ->

    view

    (

    'posts/add'

    ,

    $data

    )

    ;
  47. }
  48. }

    else

    {
  49. $data

    =

    [
  50. 'title'

    =>

    (

    isset

    (

    $_POST

    [

    'title'

    ]

    )

    ? trim

    (

    $_POST

    [

    'title'

    ]

    )

    :

    ''

    )

    ,
  51. 'body'

    =>

    (

    isset

    (

    $_POST

    [

    'body'

    ]

    )

    ? trim

    (

    $_POST

    [

    'body'

    ]

    )

    :

    ''

    )
  52. ]

    ;

  53. $this

    ->

    view

    (

    'posts/add'

    ,

    $data

    )

    ;
  54. }
  55. }

  56. //show single post
  57. public

    function

    show(

    $id

    )

    {
  58. $post

    =

    $this

    ->

    postModel

    ->

    getPostById

    (

    $id

    )

    ;
  59. $user

    =

    $this

    ->

    userModel

    ->

    getUserById

    (

    $post

    ->

    user_id

    )

    ;

  60. $data

    =

    [
  61. 'post'

    =>

    $post

    ,
  62. 'user'

    =>

    $user
  63. ]

    ;

  64. $this

    ->

    view

    (

    'posts/show'

    ,

    $data

    )

    ;
  65. }

  66. //edit post
  67. public

    function

    edit(

    $id

    )

    {
  68. if

    (

    $_SERVER

    [

    'REQUEST_METHOD'

    ]

    ==

    'POST'

    )

    {
  69. $_POST

    =

    filter_input_array

    (

    INPUT_POST,

    FILTER_SANITIZE_STRING)

    ;
  70. $data

    =

    [
  71. 'id'

    =>

    $id

    ,
  72. 'title'

    =>

    trim

    (

    $_POST

    [

    'title'

    ]

    )

    ,
  73. 'body'

    =>

    trim

    (

    $_POST

    [

    'body'

    ]

    )

    ,
  74. 'user_id'

    =>

    $_SESSION

    [

    'user_id'

    ]

    ,
  75. 'title_err'

    =>

    ''

    ,
  76. 'body_err'

    =>

    ''

    ,
  77. ]

    ;
  78. //validate the title
  79. if

    (

    empty

    (

    $data

    [

    'title'

    ]

    )

    )

    {
  80. $data

    [

    'title_err'

    ]

    =

    'Please enter post title'

    ;
  81. }
  82. //validate the body
  83. if

    (

    empty

    (

    $data

    [

    'body'

    ]

    )

    )

    {
  84. $data

    [

    'body_err'

    ]

    =

    'Please enter the post content'

    ;
  85. }

  86. //validate error free
  87. if

    (

    empty

    (

    $data

    [

    'title_err'

    ]

    )

    &&

    empty

    (

    $data

    [

    'body_err'

    ]

    )

    )

    {
  88. if

    (

    $this

    ->

    postModel

    ->

    updatePost

    (

    $data

    )

    )

    {
  89. flash(

    'post_message'

    ,

    'Your post have been updated'

    )

    ;
  90. redirect(

    'posts'

    )

    ;
  91. }

    else

    {
  92. die

    (

    'something went wrong'

    )

    ;
  93. }

  94. //laod view with error
  95. }

    else

    {
  96. $this

    ->

    view

    (

    'posts/edit'

    ,

    $data

    )

    ;
  97. }
  98. }

    else

    {
  99. //check for the owner and call method from post model
  100. $post

    =

    $this

    ->

    postModel

    ->

    getPostById

    (

    $id

    )

    ;
  101. if

    (

    $post

    ->

    user_id

    !=

    $_SESSION

    [

    'user_id'

    ]

    )

    {
  102. redirect(

    'posts'

    )

    ;
  103. }
  104. $data

    =

    [
  105. 'id'

    =>

    $id

    ,
  106. 'title'

    =>

    $post

    ->

    title

    ,
  107. 'body'

    =>

    $post

    ->

    body
  108. ]

    ;

  109. $this

    ->

    view

    (

    'posts/edit'

    ,

    $data

    )

    ;
  110. }
  111. }

  112. //delete post
  113. public

    function

    delete(

    $id

    )

    {
  114. if

    (

    $_SERVER

    [

    'REQUEST_METHOD'

    ]

    ==

    'POST'

    )

    {
  115. //check for owner
  116. $post

    =

    $this

    ->

    postModel

    ->

    getPostById

    (

    $id

    )

    ;
  117. if

    (

    $post

    ->

    user_id

    !=

    $_SESSION

    [

    'user_id'

    ]

    )

    {
  118. redirect(

    'posts'

    )

    ;
  119. }

  120. //call delete method from post model
  121. if

    (

    $this

    ->

    postModel

    ->

    deletePost

    (

    $id

    )

    )

    {
  122. flash(

    'post_message'

    ,

    'Post Removed'

    )

    ;
  123. redirect(

    'posts'

    )

    ;
  124. }

    else

    {
  125. die

    (

    'something went wrong'

    )

    ;
  126. }
  127. }

    else

    {
  128. redirect(

    'posts'

    )

    ;
  129. }
  130. }
  131. }


Users.php



  1. <?php
  2. class

    Users extends

    Controller{
  3. public

    function

    __construct(

    )
  4. {
  5. $this

    ->

    userModel

    =

    $this

    ->

    model

    (

    'User'

    )

    ;
  6. }

  7. public

    function

    register(

    )

    {
  8. if

    (

    $_SERVER

    [

    'REQUEST_METHOD'

    ]

    ==

    'POST'

    )

    {
  9. // process form
  10. $_POST

    =

    filter_input_array

    (

    INPUT_POST,

    FILTER_SANITIZE_STRING)

    ;
  11. $data

    =

    [
  12. 'name'

    =>

    trim

    (

    $_POST

    [

    'name'

    ]

    )

    ,
  13. 'email'

    =>

    trim

    (

    $_POST

    [

    'email'

    ]

    )

    ,
  14. 'password'

    =>

    trim

    (

    $_POST

    [

    'password'

    ]

    )

    ,
  15. 'confirm_password'

    =>

    trim

    (

    $_POST

    [

    'confirm_password'

    ]

    )

    ,
  16. 'name_err'

    =>

    ''

    ,
  17. 'email_err'

    =>

    ''

    ,
  18. 'password_err'

    =>

    ''

    ,
  19. 'confirm_password_err'

    =>

    ''
  20. ]

    ;

  21. //valide name
  22. if

    (

    empty

    (

    $data

    [

    'name'

    ]

    )

    )

    {
  23. $data

    [

    'name_err'

    ]

    =

    'Please enter name'

    ;
  24. }

  25. //validate email
  26. if

    (

    empty

    (

    $data

    [

    'email'

    ]

    )

    )

    {
  27. $data

    [

    'email_err'

    ]

    =

    'Please enter email'

    ;
  28. }

    else

    {
  29. //check for email
  30. if

    (

    $this

    ->

    userModel

    ->

    findUserByEmail

    (

    $data

    [

    'email'

    ]

    )

    )

    {
  31. $data

    [

    'email_err'

    ]

    =

    'Email already exist'

    ;
  32. }
  33. }

  34. //validate password
  35. if

    (

    empty

    (

    $data

    [

    'password'

    ]

    )

    )

    {
  36. $data

    [

    'password_err'

    ]

    =

    'Please enter your password'

    ;
  37. }

    elseif

    (

    strlen

    (

    $data

    [

    'password'

    ]

    )

    <

    6

    )

    {
  38. $data

    [

    'password_err'

    ]

    =

    'Password must be atleast six characters'

    ;
  39. }

  40. //validate confirm password
  41. if

    (

    empty

    (

    $data

    [

    'confirm_password'

    ]

    )

    )

    {
  42. $data

    [

    'confirm_password_err'

    ]

    =

    'Please confirm password'

    ;
  43. }

    else

    {
  44. if

    (

    $data

    [

    'password'

    ]

    !=

    $data

    [

    'confirm_password'

    ]

    )
  45. {
  46. $data

    [

    'confirm_password_err'

    ]

    =

    'Password does not match'

    ;
  47. }
  48. }

  49. //make sure error are empty
  50. if

    (

    empty

    (

    $data

    [

    'name_err'

    ]

    )

    &&

    empty

    (

    $data

    [

    'email_err'

    ]

    )

    &&

    empty

    (

    $data

    [

    'password_err'

    ]

    )

    &&

    empty

    (

    $data

    [

    'password_confirm_err'

    ]

    )

    )

    {
  51. $data

    [

    'password'

    ]

    =

    password_hash(

    $data

    [

    'password'

    ]

    ,

    PASSWORD_DEFAULT)

    ;
  52. if

    (

    $this

    ->

    userModel

    ->

    register

    (

    $data

    )

    )

    {
  53. flash(

    'register_success'

    ,

    'you are registerd you can login now'

    )

    ;
  54. redirect(

    'users/login'

    )

    ;
  55. }
  56. }

    else

    {
  57. $this

    ->

    view

    (

    'users/register'

    ,

    $data

    )

    ;
  58. }
  59. }

    else

    {
  60. //init data
  61. $data

    =

    [
  62. 'name'

    =>

    ''

    ,
  63. 'email'

    =>

    ''

    ,
  64. 'password'

    =>

    ''

    ,
  65. 'confirm_password'

    =>

    ''

    ,
  66. 'name_err'

    =>

    ''

    ,
  67. 'email_err'

    =>

    ''

    ,
  68. 'password_err'

    =>

    ''

    ,
  69. 'confirm_password_err'

    =>

    ''
  70. ]

    ;
  71. //load view
  72. $this

    ->

    view

    (

    'users/register'

    ,

    $data

    )

    ;
  73. }
  74. }

  75. public

    function

    login(

    )

    {
  76. if

    (

    $_SERVER

    [

    'REQUEST_METHOD'

    ]

    ==

    'POST'

    )

    {
  77. // process form
  78. $_POST

    =

    filter_input_array

    (

    INPUT_POST,

    FILTER_SANITIZE_STRING)

    ;
  79. $data

    =

    [
  80. 'email'

    =>

    trim

    (

    $_POST

    [

    'email'

    ]

    )

    ,
  81. 'password'

    =>

    trim

    (

    $_POST

    [

    'password'

    ]

    )

    ,
  82. 'email_err'

    =>

    ''

    ,
  83. 'password_err'

    =>

    ''
  84. ]

    ;

  85. //validate email
  86. if

    (

    empty

    (

    $data

    [

    'email'

    ]

    )

    )

    {
  87. $data

    [

    'email_err'

    ]

    =

    'Please enter email'

    ;
  88. }

    else

    {
  89. if

    (

    $this

    ->

    userModel

    ->

    findUserByEmail

    (

    $data

    [

    'email'

    ]

    )

    )

    {
  90. //user found
  91. }

    else

    {
  92. $data

    [

    'email_err'

    ]

    =

    'User not found'

    ;
  93. }
  94. }

  95. //validate password
  96. if

    (

    empty

    (

    $data

    [

    'password'

    ]

    )

    )

    {
  97. $data

    [

    'password_err'

    ]

    =

    'Please enter your password'

    ;
  98. }

    elseif

    (

    strlen

    (

    $data

    [

    'password'

    ]

    )

    <

    6

    )

    {
  99. $data

    [

    'password_err'

    ]

    =

    'Password must be atleast six characters'

    ;
  100. }

  101. //make sure error are empty
  102. if

    (

    empty

    (

    $data

    [

    'email_err'

    ]

    )

    &&

    empty

    (

    $data

    [

    'password_err'

    ]

    )

    )

    {
  103. $loggedInUser

    =

    $this

    ->

    userModel

    ->

    login

    (

    $data

    [

    'email'

    ]

    ,

    $data

    [

    'password'

    ]

    )

    ;
  104. if

    (

    $loggedInUser

    )

    {
  105. //create session
  106. $this

    ->

    createUserSession

    (

    $loggedInUser

    )

    ;
  107. }

    else

    {
  108. $data

    [

    'password_err'

    ]

    =

    'Password incorrect'

    ;
  109. $this

    ->

    view

    (

    'users/login'

    ,

    $data

    )

    ;
  110. }
  111. }

    else

    {
  112. $this

    ->

    view

    (

    'users/login'

    ,

    $data

    )

    ;
  113. }

  114. }

    else

    {
  115. //init data f f
  116. $data

    =

    [
  117. 'email'

    =>

    ''

    ,
  118. 'password'

    =>

    ''

    ,
  119. 'email_err'

    =>

    ''

    ,
  120. 'password_err'

    =>

    ''
  121. ]

    ;
  122. //load view
  123. $this

    ->

    view

    (

    'users/login'

    ,

    $data

    )

    ;
  124. }
  125. }

  126. //setting user section variable
  127. public

    function

    createUserSession(

    $user

    )

    {
  128. $_SESSION

    [

    'user_id'

    ]

    =

    $user

    ->

    id

    ;
  129. $_SESSION

    [

    'name'

    ]

    =

    $user

    ->

    name

    ;
  130. $_SESSION

    [

    'email'

    ]

    =

    $user

    ->

    email

    ;
  131. redirect(

    'posts/index'

    )

    ;
  132. }

  133. //logout and destroy user session
  134. public

    function

    logout(

    )

    {
  135. unset

    (

    $_SESSION

    [

    'user_id'

    ]

    )

    ;
  136. unset

    (

    $_SESSION

    [

    'name'

    ]

    )

    ;
  137. unset

    (

    $_SESSION

    [

    'email'

    ]

    )

    ;
  138. session_destroy

    (

    )

    ;
  139. redirect(

    'users/login'

    )

    ;
  140. }
  141. }

The application has of 2 model files for Posts and Users. The models consist all the scripts that manages the data in the database and retrieves data.

Models:

Posts.php



  1. <?php

  2. class

    Post {
  3. private

    $db

    ;
  4. public

    function

    __construct(

    )
  5. {
  6. $this

    ->

    db

    =

    new

    Database;
  7. }

  8. public

    function

    getPosts(

    )

    {
  9. $this

    ->

    db

    ->

    query

    (

    'SELECT *,
  10. posts.id as postId,
  11. user.id as userId,
  12. posts.created_at as postCreated,
  13. user.created_at as userCreated
  14. FROM posts
  15. INNER JOIN user
  16. ON posts.user_id = user.id
  17. ORDER BY posts.created_at DESC'

    )

    ;
  18. $result

    =

    $this

    ->

    db

    ->

    resultSet

    (

    )

    ;

  19. return

    $result

    ;
  20. }

  21. public

    function

    addPost(

    $data

    )

    {
  22. $this

    ->

    db

    ->

    query

    (

    'INSERT INTO posts(user_id, title, body) VALUES (:user_id, :title, :body)'

    )

    ;
  23. $this

    ->

    db

    ->

    bind

    (

    ':user_id'

    ,

    $data

    [

    'user_id'

    ]

    )

    ;
  24. $this

    ->

    db

    ->

    bind

    (

    ':title'

    ,

    $data

    [

    'title'

    ]

    )

    ;
  25. $this

    ->

    db

    ->

    bind

    (

    ':body'

    ,

    $data

    [

    'body'

    ]

    )

    ;

  26. //execute
  27. if

    (

    $this

    ->

    db

    ->

    execute

    (

    )

    )

    {
  28. return

    true

    ;
  29. }

    else

    {
  30. return

    false

    ;
  31. }
  32. }

  33. public

    function

    getPostById(

    $id

    )

    {
  34. $this

    ->

    db

    ->

    query

    (

    'SELECT * FROM posts WHERE id = :id'

    )

    ;
  35. $this

    ->

    db

    ->

    bind

    (

    ':id'

    ,

    $id

    )

    ;
  36. $row

    =

    $this

    ->

    db

    ->

    single

    (

    )

    ;

  37. return

    $row

    ;
  38. }

  39. public

    function

    updatePost(

    $data

    )

    {
  40. $this

    ->

    db

    ->

    query

    (

    'UPDATE posts SET title = :title, body = :body WHERE id = :id'

    )

    ;
  41. $this

    ->

    db

    ->

    bind

    (

    ':id'

    ,

    $data

    [

    'id'

    ]

    )

    ;
  42. $this

    ->

    db

    ->

    bind

    (

    ':title'

    ,

    $data

    [

    'title'

    ]

    )

    ;
  43. $this

    ->

    db

    ->

    bind

    (

    ':body'

    ,

    $data

    [

    'body'

    ]

    )

    ;

  44. //execute
  45. if

    (

    $this

    ->

    db

    ->

    execute

    (

    )

    )

    {
  46. return

    true

    ;
  47. }

    else

    {
  48. return

    false

    ;
  49. }
  50. }

  51. //delete a post
  52. public

    function

    deletePost(

    $id

    )

    {
  53. $this

    ->

    db

    ->

    query

    (

    'DELETE FROM posts WHERE id = :id'

    )

    ;
  54. $this

    ->

    db

    ->

    bind

    (

    ':id'

    ,

    $id

    )

    ;

  55. if

    (

    $this

    ->

    db

    ->

    execute

    (

    )

    )

    {
  56. return

    true

    ;
  57. }

    else

    {
  58. return

    false

    ;
  59. }
  60. }
  61. }

Users.php



  1. <?php
  2. class

    User {
  3. private

    $db

    ;
  4. public

    function

    __construct(

    )
  5. {
  6. $this

    ->

    db

    =

    new

    Database;
  7. }

  8. //register new user
  9. public

    function

    register(

    $data

    )

    {
  10. $this

    ->

    db

    ->

    query

    (

    'INSERT INTO user (name, email, password) VALUES (:name, :email, :password)'

    )

    ;
  11. $this

    ->

    db

    ->

    bind

    (

    ':name'

    ,

    $data

    [

    'name'

    ]

    )

    ;
  12. $this

    ->

    db

    ->

    bind

    (

    ':email'

    ,

    $data

    [

    'email'

    ]

    )

    ;
  13. $this

    ->

    db

    ->

    bind

    (

    ':password'

    ,

    $data

    [

    'password'

    ]

    )

    ;

  14. if

    (

    $this

    ->

    db

    ->

    execute

    (

    )

    )

    {
  15. return

    true

    ;
  16. }

    else

    {
  17. return

    false

    ;
  18. }
  19. }
  20. //find user by email
  21. public

    function

    findUserByEmail(

    $email

    )

    {
  22. $this

    ->

    db

    ->

    query

    (

    'SELECT * FROM user WHERE email = :email'

    )

    ;
  23. $this

    ->

    db

    ->

    bind

    (

    ':email'

    ,

    $email

    )

    ;

  24. $row

    =

    $this

    ->

    db

    ->

    single

    (

    )

    ;

  25. //check the row
  26. if

    (

    $this

    ->

    db

    ->

    rowCount

    (

    )

    >

    0

    )

    {
  27. return

    true

    ;
  28. }

    else

    {
  29. return

    false

    ;
  30. }
  31. }

  32. public

    function

    login(

    $email

    ,

    $password

    )

    {
  33. $this

    ->

    db

    ->

    query

    (

    'SELECT * FROM user where email = :email'

    )

    ;
  34. $this

    ->

    db

    ->

    bind

    (

    ':email'

    ,

    $email

    )

    ;

  35. $row

    =

    $this

    ->

    db

    ->

    single

    (

    )

    ;

  36. $hash_password

    =

    $row

    ->

    password

    ;

  37. if

    (

    password_verify(

    $password

    ,

    $hash_password

    )

    )

    {
  38. return

    $row

    ;
  39. }

    else

    {
  40. return

    false

    ;
  41. }
  42. }

  43. public

    function

    getUserById(

    $id

    )

    {
  44. $this

    ->

    db

    ->

    query

    (

    'SELECT * FROM user WHERE id = :id'

    )

    ;
  45. $this

    ->

    db

    ->

    bind

    (

    ':id'

    ,

    $id

    )

    ;

  46. $row

    =

    $this

    ->

    db

    ->

    single

    (

    )

    ;

  47. return

    $row

    ;
  48. }
  49. }

And for the views, these are the files that contain the user-interface scripts such as the login page, posts page, and registration page interfaces. The application also uses .htaccess

that rewrites the rules for redirecting the URL to the exact subdirectory/link/filename and this will give users user-friendly URLs. It uses also Bootstrap Framework that helps us make pleasant user interfaces.

Demo

This web application is free to download. Feel Free to download and modify the source code to enhance and develop your programming capabilities in PHP Language.

How to Run

Requirements
  • Download and Install any local web server such as XAMPP/WAMP.
  • Download the provided source code zip file. (download button is located below)

Installation/Setup
  1. Open your XAMPP/WAMP's Control Panel and start the Apache

    and MySQL

    .
  2. Extract the downloaded source code zip file.
  3. If you are using XAMPP, copy the extracted source code folder and paste it into the XAMPP's "htdocs" directory. And If you are using WAMP, paste it into the "www" directory.
  4. Browse the PHPMyAdmin

    in a browser. i.e.

  5. Create a new database naming shareposts

    .
  6. Import the provided SQL

    file. The file is known as shareposts.sql

    located inside the database folder.
  7. Browse the Web Application in a browser. i.e.
    .

I hope this will help you with what you are looking for and helps you to understand and learn to develop a web application using Core PHP/MVX/OOP/PDO.

Enjoy :)

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

442,401

317,942

317,951

Top