Jump to content

Php Exam - help me please :)


Recommended Posts

Hi guys,

 

Ok so in a few days i have got 2 seen exams in php. Basically i've been working all year and have had no time whatsoever to prepare!! So please if you can help me  I don't want to cheat, but i really just want someone to point me in the right direction - bear in mind i've forgotten most of the php i previously learnt.

 

For the first exam i've just gotta make a simple login to direct the correct user to some links, and most of the files are already created. I'll post as much info as i can below. Thanks in advance!!!

 

link-list server.

A Web application to is required to accept user name and password input to an HTML form and authenticate the user against a database. If the user fails authentication, return her to the login page. If the user is authenticated present the user with a list of HTML links to which she is permitted access. The application consists of the following files

 

setup.php

A script to create the data files needed by the application.

provided

 

userlinks.sqlite

SQLite database of user data

created by setup.php

 

listlinks.array

Serialised array of links

created by setup.php

 

login.html

The login screen

provided

 

userlinks.php

PHP script to authenticate user and serve lists of permitted links.

for you to write

 

Setup.php

<?php

$dbfile='userlinks.sqlite';

$lnfile='listlinks.array';

$dbh = sqlite_open($dbfile);

$sql = "DROP TABLE user;";

@sqlite_exec($dbh,$sql);

$sql = "DROP TABLE users;";

@sqlite_exec($dbh,$sql);

$sql = "CREATE TABLE users (user TEXT PRIMARY KEY,fullname TEXT,".

"pass TEXT,L0 INT,L1 INT,L2 INT,L3 INT,L4 INT,L5 INT,". "L6 INT,L7 INT,L8 INT,L9 INT);";

sqlite_exec($dbh,$sql);

$sql = "INSERT INTO users VALUES('steve',". "'Steve Smethurst','letmein',1,1,1,1,1,1,1,1,1,1);";

sqlite_exec($dbh,$sql);

$sql = "INSERT INTO users VALUES('bob',". "'Bob Glass','anchorman',1,0,0,1,1,0,1,0,1,1);";

sqlite_exec($dbh,$sql);

$sql = "INSERT INTO users VALUES('frances',". "'Frances Johnson','doesitright',1,0,1,0,1,1,1,0,1,1);";

sqlite_exec($dbh,$sql);

$sql = "INSERT INTO users VALUES('richard',". "'Richard Eskins','ontheball',0,0,0,1,1,1,1,0,0,0);";

sqlite_exec($dbh,$sql);

$sql = "INSERT INTO users VALUES('chris',". "'Chris ','neverfails',1,1,0,1,0,1,1,0,1,0);";

sqlite_exec($dbh,$sql);

$sql = "INSERT INTO users VALUES('deirdre',". "'Deirdre Hynes','makesitwork',0,1,0,1,0,1,0,1,1,1);";

sqlite_exec($dbh,$sql);

$sql = "INSERT INTO users VALUES('jonanthan',". ".'Jonathan Wilson','heresjonny',1,1,0,1,1,1,0,0,0,1);";

sqlite_exec($dbh,$sql);

$links = array(

array("http://linuxoutlaws.com/","Linux Outlaws"),

array("http://www.linuxactionshow.com/index.php", "Linux Action Show"),

array("http://www.jodcast.net/","Jodrell Bank Astronomy Podcast"),

array("http://365daysofastronomy.org/","365 Days of Astronomy"),

array("http://php.net/manual/en/index.php","PHP Language Manual"),

array("http://www.sqlite.org/lang.html","SQLite Syntax Manual"),

array("http://www.w3schools.com/js/default.asp", "W3C Schools JavaScript Tutorial"),

array("http://www.scottsigler.com/taxonomy/reverse/40", "Scott Sigler - The Future Dark Overlord"),

array("http://www.thephilrossiexperience.com/crescent/", "Phil Rossi - Darker Than Deep Space"),

array("http://escapepod.org/", "Escape Pod - The Science Fiction Podcast Magazine")

);

file_put_contents($lnfile,serialize($links));

$sql = "SELECT pass FROM users WHERE user='steve';";

$rh = sqlite_query($dbh,$sql,SQLITE_ASSOC);

$row = sqlite_fetch_array($rh);

if ($row['pass'] == 'letmein')

echo "Database has been created and tested

";

else

echo "Database does not work

";

$filestring = file_get_contents($lnfile);

$array = unserialize($filestring);

if ($array[0][1] == "Linux Outlaws")

echo "Links file has been created and tested

";

else

echo "Links file does not work

";

sqlite_close($dbh);

 

 

userlinks.php – skeleton file

<?php

# read from file and unserialise the links array

# get user & pass from http header

# open the database

# get database row for this user

# authenticate user or return to login

# print HTML page header

# print full name as heading

# print each permitted link in a numbered list

# close the database

 

Login.html

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>

<title>Login Links</title>

<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>

<meta http-equiv="expires" content="0"/>

</head>

<body>

<h3>User Login For Access to the Links Server</h3>

<form action="userlinks.php" method="POST">

<label for="user" style="display:block;">User Name</label>

<input id="user" name="user" type="text" />

<label for="pass" style="display: block;">Password</label>

<input id="pass" name="pass" type="password" />

<input type="submit" name="login" value="Login" />

</form>

</body>

</html>

 

There's quite allot more that i have missed out but i think this should give you the jist so that you can point out what i have to do and where i can start looking for the answers. Sorry for being a complete noob! I literally really want ot be a web developer but until i finish work (this summer) and go back to uni i havn't had any time to carry on learning.

 

If you need any more of the info just pm me with your e-mail and i will send over the pdf's - there are 2 though!

 

Cheers guys, Josh. 

 

p.s. I posted this on two php forums and the other one didn't do attachments but i've just seen this one does so i've uploaded the main 2 files!

 

[attachment deleted by admin]

Link to comment
Share on other sites

Firstly, this board's subject is PHP Installation & Configuration, what exactly makes you think this post belongs in the category?

 

Secondly, your not going to learn PHP well enough in two days to pass any exam on the subject, if I were you I would simply face this fact and move on, better luck next time.

 

The manual however (http://php.net/manual) is the best resource for all things PHP. Everything outlined in your post is covered in the manual.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.