Starting from:

$30

CSE383 php application Solved

Create a single php application that will return multiple different "pages" to the user based upon their input. All your work is to be done in the file index.php.  The PHP application will use a query variable called $cmd to determine which page to render. This $cmd variable is created by read the query string url. Recall anything after a "?" in the url will be passed as variables to the php program.

 

You would invoke these pages like:

 

….index.php?cmd=page1  and  ...index.php?cmd=page2

 

Here is a code snippet that shows how you will read the variable and make decisions as to what output to render.

 

<?php if ($cmd=="page1"){

?

HTML for page1

<?php

}

else if ($cmd == "page2") {

            ? 

HTML for page2 

<?php

 

 

 

} else {

? default 

<?php }?

 

 

Where $cmd is a variable that is sent to the server from the different links.

Steps:

1)    There is a ​video​ showing my working solution that you can use to help understand functionality.

2)    In your git working copy on ceclnx01, create a directory called php1. The file inside this directory shall be called index.php

3)    Edit index.php to include Create a bootstrap PHP page with a Header, Left Menu and a Main Content Area.

4)    In the Left Menu place the following three links:

a)    <a href="index.php?cmd=page1"Random Numbers</a

b)    <a href="index.php?cmd=page2"Images</a

c)    <a href="index.php?cmd=page1"Input Form</a

d)    <a href="index.php"Home</a

5)    Using your browser view this page and get the HTML correct before adding any html.

6)    Even though you have created a php file, there is no php code yet. At the top of the index.php file put in the following code:

<?php

/*

YOUR COMMENT BLOCK HERE (name, date, assignment..)

*/

 

session_start();                        //create a session

 

//initialize number of visits session variable

$numVisits = 0; if (isset($_SESSION['num'])) {                     $_SESSION['num']++;

                     $numVisits = $_SESSION['num'];

} else {

                   $numVisits = 0;

                  $_SESSION['num'] = 0;



//see if the cmd get variable is passed into the program.

$cmd = "";

if (isset($_GET['cmd'])) {

           $cmd =htmlspecialchars($_GET['cmd']);

           if ($cmd != "page1" && $cmd != "page2" && $cmd != "page3") {

                 $cmd = "";

             }

}

 

//YOU WILL PUT YOUR FORM HANDLING CODE HERE

?

 

Make sure you understand this code.

 

5) Now inside the section for your main content area, put in code to display the following: a) Default Page

Display, in a well formatted table, 5 different interesting values from the $_SERVER superglobal.

b)    page1

for page 1, use PHP to In this area use PHP to generate 100 random numbers with each number having different font colors.

c)    STOP HERE for the In CLASS LAB AND DEMONSTRATE TO INSTRUCTOR!!!!!!d) page2

Use PHP to randomly select and insert one of three image tags to files stored on your server.

i)              load 3 images into a subdirectory'

ii)             create an array in your code with the images name

iii)            use a random variable to select one of the image names to put in the image tag. e) page3

i)         Display a simple HTML form that simply asks the user for their name.  On submit the form will submit back to index.php. Blank input is legal.

ii)        In the section above labeled "YOU WILL PUT YOUR FORM HANDLING CODE

HERE" put in code that will look to see if the user submitted a form with their name.

1)    assuming your input tag is <input type="text" name="user" then the value would be $_GET['user'];

2)    Make sure to use htmlspecialchars to protect this variable.

3)    Assign the submitted value to the session variable called "user" iii)   At the bottom of the menu section display 

1) the users name (from the session variable and obviously only if the session value is set) 2) The number of visits.

f)        Make sure to commit all your code to GIT

g)       Make sure it is clean, well commented, well indented

h)       Submit working links via canvas to:

i)        your index.php file

                    ii)      your gitlab repository

More products