Skip to content

Student Listing: Adding User Logins - Page Titles

Let's create a script for holding page title constants for some of our scripts.

Create a new script called pagetitles.php and add the following function code:

pagetitles.php - Student Listing: Complete Code Listing

1
2
3
4
5
6
7
8
<?php
    // Page Titles
    define('SL_SIGNUP_PAGE', 'Student Listing - Sign Up');
    define('SL_LOGIN_PAGE', 'Student Listing - Login');
    define('SL_UNAUTHORIZED_ACCESS_PAGE', 'Student Listing - Unauthorized Access');
    define('SL_ADD_PAGE', 'Student Listing - Add Student');
    define('SL_EDIT_PAGE', 'Student Listing - Edit Student');
    define('SL_REMOVE_PAGE', 'Student Listing - Remove Student');

Notice above, not only do we have definitions for the three pages we already created (addstudent.php, editstudent.php, and removestudent.php), but we also have threee new scripts we will need to write that will use the page title constants.

Therefore, modify the following scripts as follows to use the page title constants:

addstudent.php - Student Listing: Modify code to use page title constant

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
    require_once('pagetitles.php');
    $page_title = SL_ADD_PAGE;
    require_once('authorizeaccess.php');
?>
<!DOCTYPE html>
<html>
  <head>
    <title><?= $page_title ?></title>
    <link rel="stylesheet"
          href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
          integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"
          crossorigin="anonymous">
  </head>
  <body>
    <div class="card">
      <div class="card-body">
        <h1><?= $page_title ?></h1>
        <nav class="nav">
          <a class="nav-link" href="index.php">Students</a>
        </nav>
        <hr/>

editstudent.php - Student Listing: Modify code to use page title constant

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
    require_once('pagetitles.php');
    $page_title = SL_EDIT_PAGE;
    require_once('authorizeaccess.php');
?>
<!DOCTYPE html>
<html>
  <head>
    <title><?= $page_title ?></title>
    <link rel="stylesheet"
          href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
          integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"
          crossorigin="anonymous">
  </head>
  <body>
    <div class="card">
      <div class="card-body">
        <h1><?= $page_title ?></h1>
        <nav class="nav">
          <a class="nav-link" href="index.php">Students</a>
        </nav>
        <hr/>

removestudent.php - Student Listing: Modify code to use page title constant

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
<?php
    require_once('pagetitles.php');
    $page_title = SL_REMOVE_PAGE;
    require_once('authorizeaccess.php');
?>
<!DOCTYPE html>
<html>
  <head>
    <title><?= $page_title ?></title>
    <link rel="stylesheet"
          href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
          integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"
          crossorigin="anonymous">
  </head>
  <body>
    <div class="card">
      <div class="card-body">
        <h1><?= $page_title ?></h1>