/    Sign up×
Community /Pin to ProfileBookmark

Zend PHP 5 Certification: Exam Question Assistance (06 May 2010)

I have just sat, and passed, another mock exam for the Zend PHP certification. The following questions came up in the test and I wondered if anyone would be able to help me out in obtaining the answers and the reasons (if possible). 🙂

[code=php]
<?php
function redirect($url) {
// Check to make sure we haven’t already sent
// the header:

if(???????) {
header(“Location: $url”);
}
}

?>
[/code]

What conditional should replace the ????? above?

Answers:

[LIST]

  • [*]

    !in_array(“Location: $url”, headers_list())


  • [*]

    !header_exists(“Location: $url”)


  • [*]

    !header_location($url)


  • [*]

    $_SERVER[‘HTTP_LOCATION’] != $url

  • [/LIST]
    =========================================================

    [code=php]
    <?php
    header(“Location: {$_GET[‘url’]}”);
    ?>
    [/code]

    Which of the following values of $_GET[‘url’] would cause session fixation?

    Answers:

    [LIST]

  • [*]

    Session Fixation is not possible with this code snippet


  • [*]

    [url]http://www.zend.com/?PHPSESSID=123[/url]


  • [*]

    PHPSESSID%611243


  • [*]

    Set-Cookie%3A+PHPSESSID%611234


  • [*]

    http%3A%2F%2Fwww.zend.com%2F%0D%0ASetCookie%3A+PHPSESSID%611234


  • [/LIST]

    =========================================================

    If regular expressions must be used, in general which type of regular expression functions available to PHP is preferred for performance reasons?

    [LIST]

  • [*]

    strtok() using regular expressions


  • [*]

    preg_* regular expression functions

  • [*]

    parse_str() using regular expressions

  • [*]

    strregex* regular expression functions

  • [*]

    ereg* regular expression functions

  • [/LIST]

    =========================================================

    Many thanks,
    Picco

    to post a comment
    PHP

    1 Comments(s)

    Copy linkTweet thisAlerts:
    @NogDogMay 07.2010 — 
  • 1. Of the 3 functions listed in the answer, only headers_list() is in the manual. But it does not answer the question posed by the code comment, which would be better addressed by the headers_sent() function, in my opinion.


  • 2. I would think only the first URL would, as the others would not actually be well-formed URLs with a fixable query string.


  • 3. I know that the preg_*() (PCRE) functions are preferred over the ereg_*() functions (which are deprecated), while strregex() is not defined and the other two functions are not really regexp functions (though strtok() is somewhat similar and might be preferred in certain specific circumstances where you might consider using a regexp function).
  • ×

    Success!

    Help @crmpicco spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.5,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...