$HTTP_USER_AGENT not available from within header.html?

$HTTP_USER_AGENT not available from within header.html?

by Alan Chambers -
Number of replies: 2

placing

print "$HTTP_USER_AGENT";

in the body of the /theme/standard/header.html file does not return anything. I need to do a browser picker using

if (strstr($HTTP_USER_AGENT,"MSIE")) {
    print "Your browser is Internet Explorer";
}elseif (strstr($HTTP_USER_AGENT,"Mozilla")) {
    print "Your browser is  Netscape";
}

Where in the moodle code is the return of $HTTP_USER_AGENT stopped from being called from header.html OR does anyone have a solution to this problem?

Average of ratings: -
In reply to Alan Chambers

Re: $HTTP_USER_AGENT not available from within header.html?

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
You should access it using this syntax:

$_SERVER['HTTP_USER_AGENT']

...this will work in any context. On a related note, I'm currently trying out this code in lib/setup.php to let Google into the moodle.org forums as a guest:

    if (empty($_SESSION['USER'])) {
        if (!empty($_SERVER['HTTP_USER_AGENT'])) {
            if (strpos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false ) {
                $USER->id = 153;
                $USER->firstname = "Guest";
                $USER->lastname = "User";
                $USER->username = "guest";
                $USER->email = "guest@moodle.org";
                $USER->loggedin = true;
                $USER->confirmed = 1;
                $USER->site = $CFG->wwwroot;
            }
        }
    }


I'll let you know how it goes and might make it an admin option.
In reply to Martin Dougiamas

Re: $HTTP_USER_AGENT not available from within header.html?

by Alan Chambers -

Thank you Martin. It all works now!

See a friend is online in the moodle application, click their name , their user profile is displayed with extra button "Chat to me Now". On selecting the button the friend gets (on their next action in moodle) in IE a predetemined chat opens with both parties within it, or on Netscape a button appears in the header "Alan wants to chat with you Now. Click to chat." then the chat window opens. [Netscape will not open unrequested popups].

Solves client request but I would like something like a private chat to open, not a general social chat I have already set up.

Again thank you

Code attached.