cs571_13fa-final-horowitz-s2V2-answers.pdf

A z0 9a z0 9a z0 9a z24 if pregmatchregexp string

Info icon This preview shows pages 5–9. Sign up to view the full content.

$regexp = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0- 9_]+)*[.][A-z]{2,4}$/"; if (preg_match($regexp, $string)) { echo "Email address is valid."; } else { echo "Email address is not valid."; } ?> 7. [5 pts] Determine what the following PHP function returns: function doit($x) {return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)? (/.*)?$|i', $x); } a. What is the result when the input $x is: b. What is the result when the input $x is:
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

6 c. In one sentence explain what the function does and what you would use it for? Answer: a. false b. true (need to check!!) c. Validates a URL Cookies and Privacy [15 pts] <html><head><title>User Logon</title></head> <body> <h2>User Login </h2> <form name="login" method="post" action="login.php"> Username: <input type="text" name="username"><br> Password: <input type="password" name="password"><br> Remember Me: <input type="checkbox" name="rememberme" value="1"><br> <input type="submit" name="submit" value="Login!"> </form></body></html> Below is the source code for login.php. Fill in the missing code and answer the questions below. <?php /* These are our valid username and passwords */
Image of page 6
7 $user = 'jonny4'; $pass = 'delafoo'; if (isset($_POST['username']) && isset($_POST['password')) { if (($_POST['username'] == $user) && ($_POST['password'] == $pass)) { if (isset($_POST[' rememberme '])) { setcookie('username', $_POST['username'], time()+60*60*24*365, '/account', ' '); setcookie('password', md5($_POST['password']), time()+60*60*24*365, '/account', ' '); } else { setcookie('username', $_POST['username'], false, '/account', ' '); setcookie('password', md5($_POST['password']), false, '/account', ' '); } header('Location: index.php'); } else { echo ' Username/Password Invalid '; } } else { echo 'You must supply a username and password.'; } ?> 8. [5 pts] If rememberme is chosen, how long will the cookie last? Answer: 1 year 9. [5 pts] If rememberme is NOT chosen, how long will the cookie last? Answer: when the browser closes 10. [5 pts] What is md5? Answer: a function which produces a hash value for the password XML Schemas [15 pts] Below is an XML schema that describes a Bookstore. Answer the questions below. <?xml version="1.0"?> <xsd:schema xmlns:xsd=" " targetNamespace=" "
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

8 xmlns=" " elementFormDefault="qualified" > <xsd:element name="BookStore"> <xsd:complexType> <xsd:sequence> <xsd:element ref="Book" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="Book"> <xsd:complexType> <xsd:sequence> <xsd:element ref="Title" minOccurs="1" maxOccurs="1"/> <xsd:element ref="Author" minOccurs="1" maxOccurs="1"/>
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '07
  • Papa
  • Ajax

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern