time = time(); $this->startSession(); } /** * startSession - Performs all the actions necessary to * initialize this session object. Tries to determine if the * the user has logged in already, and sets the variables * accordingly. Also takes advantage of this page load to * update the active visitors tables. */ function startSession(){ global $database; //The database connection session_start(); //Tell PHP to start the session /* Determine if user is logged in */ $this->logged_in = $this->checkLogin(); /** * Set guest value to users not logged in, and update * active guests table accordingly. */ if(!$this->logged_in){ $this->username = $_SESSION['username'] = GUEST_NAME; $this->userlevel = GUEST_LEVEL; $database->addActiveGuest($_SERVER['REMOTE_ADDR'], $this->time); } /* Update users last active timestamp */ else{ $database->addActiveUser($this->username, $this->time); } /* Remove inactive visitors from database */ $database->removeInactiveUsers(); $database->removeInactiveGuests(); /* Set referrer page */ if(isset($_SESSION['url'])){ $this->referrer = $_SESSION['url']; }else{ $this->referrer = "/"; } /* Set current url */ $this->url = $_SESSION['url'] = $_SERVER['PHP_SELF']; } /** * checkLogin - Checks if the user has already previously * logged in, and a session with the user has already been * established. Also checks to see if user has been remembered. * If so, the database is queried to make sure of the user's * authenticity. Returns true if the user has logged in. */ function checkLogin(){ global $database; //The database connection /* Check if user has been remembered */ if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookid'])){ $this->username = $_SESSION['username'] = $_COOKIE['cookname']; $this->userid = $_SESSION['userid'] = $_COOKIE['cookid']; } /* Username and userid have been set and not guest */ if(isset($_SESSION['username']) && isset($_SESSION['userid']) && $_SESSION['username'] != GUEST_NAME){ /* Confirm that username and userid are valid */ if($database->confirmUserID($_SESSION['username'], $_SESSION['userid']) != 0){ /* Variables are incorrect, user not logged in */ unset($_SESSION['username']); unset($_SESSION['userid']); return false; } /* User is logged in, set class variables */ $this->userinfo = $database->getUserInfo($_SESSION['username']); $this->username = $this->userinfo['username']; $this->userid = $this->userinfo['userid']; $this->userlevel = $this->userinfo['userlevel']; return true; } /* User not logged in */ else{ return false; } } /** * login - The user has submitted his username and password * through the login form, this function checks the authenticity * of that information in the database and creates the session. * Effectively logging in the user if all goes well. */ function login($subuser, $subpass, $subremember){ global $database, $form; //The database and form object /* Username error checking */ $field = "user"; //Use field name for username if(!$subuser || strlen($subuser = trim($subuser)) == 0){ $form->setError($field, "* Username not entered"); } else{ /* Check if username is not alphanumeric */ if(!eregi("^([0-9a-z])*$", $subuser)){ $form->setError($field, "* only letters and numbers allowed and no spaces"); } } /* Password error checking */ $field = "pass"; //Use field name for password if(!$subpass){ $form->setError($field, "* Password not entered"); } /* Return if form errors exist */ if($form->num_errors > 0){ return false; } /* Checks that username is in database and password is correct */ $subuser = stripslashes($subuser); $result = $database->confirmUserPass($subuser, md5($subpass)); /* Check error codes */ if($result == 1){ $field = "user"; $form->setError($field, "* Username not found"); } else if($result == 2){ $field = "pass"; $form->setError($field, "* Invalid password"); } /* Return if form errors exist */ if($form->num_errors > 0){ return false; } /* Username and password correct, register session variables */ $this->userinfo = $database->getUserInfo($subuser); $this->username = $_SESSION['username'] = $this->userinfo['username']; $this->userid = $_SESSION['userid'] = $this->generateRandID(); $this->userlevel = $this->userinfo['userlevel']; /* Insert userid into database and update active users table */ $database->updateUserField($this->username, "userid", $this->userid); $database->addActiveUser($this->username, $this->time); $database->removeActiveGuest($_SERVER['REMOTE_ADDR']); /** * This is the cool part: the user has requested that we remember that * he's logged in, so we set two cookies. One to hold his username, * and one to hold his random value userid. It expires by the time * specified in constants.php. Now, next time he comes to our site, we will * log him in automatically, but only if he didn't log out before he left. */ if($subremember){ setcookie("cookname", $this->username, time()+COOKIE_EXPIRE, COOKIE_PATH); setcookie("cookid", $this->userid, time()+COOKIE_EXPIRE, COOKIE_PATH); } /* Login completed successfully */ return true; } /** * logout - Gets called when the user wants to be logged out of the * website. It deletes any cookies that were stored on the users * computer as a result of him wanting to be remembered, and also * unsets session variables and demotes his user level to guest. */ function logout(){ global $database; //The database connection /** * Delete cookies - the time must be in the past, * so just negate what you added when creating the * cookie. */ if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookid'])){ setcookie("cookname", "", time()-COOKIE_EXPIRE, COOKIE_PATH); setcookie("cookid", "", time()-COOKIE_EXPIRE, COOKIE_PATH); } /* Unset PHP session variables */ unset($_SESSION['username']); unset($_SESSION['userid']); /* Reflect fact that user has logged out */ $this->logged_in = false; /** * Remove from active users table and add to * active guests tables. */ $database->removeActiveUser($this->username); $database->addActiveGuest($_SERVER['REMOTE_ADDR'], $this->time); /* Set user level to guest */ $this->username = GUEST_NAME; $this->userlevel = GUEST_LEVEL; } /** * register - Gets called when the user has just submitted the * registration form. Determines if there were any errors with * the entry fields, if so, it records the errors and returns * 1. If no errors were found, it registers the new user and * returns 0. Returns 2 if registration failed. */ function register($subuser, $subpass, $subemail){ global $database, $form, $mailer; //The database, form and mailer object /* Username error checking */ $field = "user"; //Use field name for username if(!$subuser || strlen($subuser = trim($subuser)) == 0){ $form->setError($field, "* Username not entered"); } else{ /* Spruce up username, check length */ $subuser = stripslashes($subuser); if(strlen($subuser) < 5){ $form->setError($field, "* Username below 5 characters"); } else if(strlen($subuser) > 30){ $form->setError($field, "* Username above 30 characters"); } /* Check if username is not alphanumeric */ else if(!eregi("^([0-9a-z])+$", $subuser)){ $form->setError($field, "* * only letters and numbers allowed and no spaces"); } /* Check if username is reserved */ else if(strcasecmp($subuser, GUEST_NAME) == 0){ $form->setError($field, "* Username reserved word"); } /* Check if username is already in use */ else if($database->usernameTaken($subuser)){ $form->setError($field, "* Username already in use"); } /* Check if username is banned */ else if($database->usernameBanned($subuser)){ $form->setError($field, "* Username banned"); } } /* Password error checking */ $field = "pass"; //Use field name for password if(!$subpass){ $form->setError($field, "* Password not entered"); } else{ /* Spruce up password and check length*/ $subpass = stripslashes($subpass); if(strlen($subpass) < 4){ $form->setError($field, "* Password too short"); } /* Check if password is not alphanumeric */ else if(!eregi("^([0-9a-z])+$", ($subpass = trim($subpass)))){ $form->setError($field, "* * only letters and numbers allowed and no spaces"); } /** * Note: I trimmed the password only after I checked the length * because if you fill the password field up with spaces * it looks like a lot more characters than 4, so it looks * kind of stupid to report "password too short". */ } /* Email error checking */ $field = "email"; //Use field name for email if(!$subemail || strlen($subemail = trim($subemail)) == 0){ $form->setError($field, "* Email not entered"); } else{ /* Check if valid email address */ $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*" ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*" ."\.([a-z]{2,}){1}$"; if(!eregi($regex,$subemail)){ $form->setError($field, "* Email invalid"); } $subemail = stripslashes($subemail); } /* Errors exist, have user correct them */ if($form->num_errors > 0){ return 1; //Errors with form } /* No errors, add the new account to the */ else{ if($database->addNewUser($subuser, md5($subpass), $subemail)){ if(EMAIL_WELCOME){ $mailer->sendWelcome($subuser,$subemail,$subpass); } return 0; //New user added succesfully }else{ return 2; //Registration attempt failed } } } /** * editAccount - Attempts to edit the user's account information * including the password, which it first makes sure is correct * if entered, if so and the new password is in the right * format, the change is made. All other fields are changed * automatically. */ function editAccount($subcurpass, $subnewpass, $subemail){ global $database, $form; //The database and form object /* New password entered */ if($subnewpass){ /* Current Password error checking */ $field = "curpass"; //Use field name for current password if(!$subcurpass){ $form->setError($field, "* Current Password not entered"); } else{ /* Check if password too short or is not alphanumeric */ $subcurpass = stripslashes($subcurpass); if(strlen($subcurpass) < 4 || !eregi("^([0-9a-z])+$", ($subcurpass = trim($subcurpass)))){ $form->setError($field, "* Current Password incorrect"); } /* Password entered is incorrect */ if($database->confirmUserPass($this->username,md5($subcurpass)) != 0){ $form->setError($field, "* Current Password incorrect"); } } /* New Password error checking */ $field = "newpass"; //Use field name for new password /* Spruce up password and check length*/ $subpass = stripslashes($subnewpass); if(strlen($subnewpass) < 4){ $form->setError($field, "* New Password too short"); } /* Check if password is not alphanumeric */ else if(!eregi("^([0-9a-z])+$", ($subnewpass = trim($subnewpass)))){ $form->setError($field, "* New Password not alphanumeric"); } } /* Change password attempted */ else if($subcurpass){ /* New Password error reporting */ $field = "newpass"; //Use field name for new password $form->setError($field, "* New Password not entered"); } /* Email error checking */ $field = "email"; //Use field name for email if($subemail && strlen($subemail = trim($subemail)) > 0){ /* Check if valid email address */ $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*" ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*" ."\.([a-z]{2,}){1}$"; if(!eregi($regex,$subemail)){ $form->setError($field, "* Email invalid"); } $subemail = stripslashes($subemail); } /* Errors exist, have user correct them */ if($form->num_errors > 0){ return false; //Errors with form } /* Update password since there were no errors */ if($subcurpass && $subnewpass){ $database->updateUserField($this->username,"password",md5($subnewpass)); } /* Change Email */ if($subemail){ $database->updateUserField($this->username,"email",$subemail); } /* Success! */ return true; } /** * isAdmin - Returns true if currently logged in user is * an administrator, false otherwise. */ function isAdmin(){ return ($this->userlevel == ADMIN_LEVEL || $this->username == ADMIN_NAME); } /** * generateRandID - Generates a string made up of randomized * letters (lower and upper case) and digits and returns * the md5 hash of it to be used as a userid. */ function generateRandID(){ return md5($this->generateRandStr(16)); } /** * generateRandStr - Generates a string made up of randomized * letters (lower and upper case) and digits, the length * is a specified parameter. */ function generateRandStr($length){ $randstr = ""; for($i=0; $i<$length; $i++){ $randnum = mt_rand(0,61); if($randnum < 10){ $randstr .= chr($randnum+48); }else if($randnum < 36){ $randstr .= chr($randnum+55); }else{ $randstr .= chr($randnum+61); } } return $randstr; } }; /** * Initialize session object - This must be initialized before * the form object because the form uses session variables, * which cannot be accessed unless the session has started. */ $session = new Session; /* Initialize form object */ $form = new Form; ?> Ricky Gervais... Obviously. " ."" .""; $forminput = "" ."" ."" . ""; if($session->logged_in){ $toptagline ="" ."" .""; $forminput = ""; } else{ /** * User not logged in, display the login form. * If user has already tried to login, but errors were * found, display the total number of errors. * If errors occurred, they will be displayed. */ if($form->num_errors > 0){ $errorline = ""; } } $membersline = "There are ".$database->getNumMembers()." members signed up to Ricky Gervais.Com - ". $database->num_active_users ." are signed in now and there are " . $database->num_active_guests. " people just visiting"; ?>

With three shows on American TV, a forthcoming movie debut and this month's first UK screening of Homer Simpson: This is Your Wife - written by and starring the co-creator of The Office and Extras - Ricky Gervais is Hollywood's hottest Brit. How did that happen?
Story by Alex Bilmes Portrait by Olaf Heine

Upstairs at a near-deserted Groucho Club on an abstemious January afternoon, Ricky Gervais is getting to his feet and putting on his coat while running through a mental checklist, awarding himself points out of ten tor his interview technique. "Pretentiousness?" Brief pause, slightly pained expression. "Nine, I reckon," I nod. "Egomania?" Another pause, a wince. "Yeah, nine as well" Again, no argument from me. "The thing about these things," says Gervais, "is you have to try to remember if you've made a fool of yourself. At the end of the day, it's however the journalist decides to take it."

Over to me, then. Had he been particularly pretentious? ah no, Not at all. Those Kierkegaard and Nietzsche quotations? Perfectly understandable given the topic of conversation (TV sitcoms), and of course he demonstrated a heart-warming common touch, too, by tossing off references to Noel Edmonds and Big Brother~s Little Brother and, you know, Jean-Paul Sartre.

And egomaniacal? Never! Unless, that is. one considers it vainglorious for a 44-year-old British comedian to claim his Hollywood cachet rivals that of Tom Cruise or Jennifer Aniston, or that his comedy peers are American genii Matt Groening, Garry Shandling and Larry David rather than humbler home-grown talents. But it seems only fair to report that much sardonic grimacing and eyebrow flashing - irony that is difficult to convey on the page - accompanied our conversations. Not to mention that hyena-on helium yelp that Gervais uses where other people content themselves with a laugh.

Ordinarily at this stage I might attempt a detailed physical description of my subject, but you already know what Ricky Gervais looks like. Unlike most famous people who are shorter, or taller, or fatter, or thinner than they appear on screen or in print, Gervais looks just like he does on telly and in the papers: he's a portly Englishman of medium height, in early middle age, with fine dark hair, a pale complexion, a parsimonious mouth and flickering piggy eyes.

He favours unremarkable V-neck sweaters over unremarkable T-shirts, teamed with unremarkable casual trousers and unremarkable sensible shoes. On cold days, he wears an unremarkable tan corduroy overcoat.

I know he finds it irritating, and I know that it's probably reductive and "lazy" (his word), but I found it hard, even at our second meeting when we were nearing five hours of taped conversation, to rid myself of the sense that I was sitting opposite his most famous creation. The voice, the accent, the mannerisms - they're all so incredibly David Brent.

He's used to this reaction. "People say, 'Oh, he talks like Brent:" says Gervais. "No, Brent talks like me. I used my voice, I exaggerated a little bit, I went a little more Reading with Brent, and I also [he begins to over-enunciate and linger over each word] trIed to slow it down so he ... is .. more ... professorial... than ... me."

It pains me to say it, but with each word spoken, he sounds more like Brent. This effect is considerably heightened if you are, as I am, facing him across an empty desk in a mostly anonymous office, while he fiddles with a mouse and glances occasionally at a computer screen, or leans back in his chair and puts his feet up, the better to contemplate life, the universe and Arrested Development's final season. Thank God he's not wearing a tie otherwise he'd probably finger it, and then I'd really be lost.

But there's no use dwelling on past glories: Gervais and I had arranged this Interview so that he could discuss his forlhcoming projects most pressingly, the episode of The Simpsons that he wrote and stars in, but also the second series of his hit sitcom, Extras, which he's writing at the moment with his partner Stephen Merchant; his cameo In For Your Consideration, the next film from Spinal Tap maestro Christopher Guest; his occasional Channel 4 interviews with his comedy heroes, Ricky Gervais Meets..., which began in January wIth Larry David and will pick up again later this year; and his ongoing role as executive producer and spiritual adviser to the hit American version of The Office.

What with his wildly successful podcasts for the Guardian's website, alongside Merchant and the idiot savant and cult hero Karl Pilkington, the past 12 months have been extraordinarily productive. "2005 was a big year," Gervais agrees, "but the biggest thing for us was that we properly broke America."

He's not exaggerating. On HBO, the channel that has also been home to The Sopranos and Sex And The City, Extras ran as part of a Sunday evening double-bill with Larry David's incomparable Curb Your Enthusiasm, beginning in late September. If anything, the reviews for the six episodes of Gervais and Merchant's toe curlingly unrestrained celebrily send-up were still more reverent than those in Britain, and HBO announced even before it had aired the first series that it would pay for a second.

Meanwhile, over on NBC, higher slakes are being played for. This is network television, available across the States, syndicating across the world and generating ad revenue undreamed of outside America. The American adaptation of The Office, much derided as an idea when it was first announced, has recently been recommissioned for a further 22 episodes, taking the total to 49.

Subtitled An American Workplace, at the time of writing it runs on Thursday nights, after another hit comedy, My Name Is Earl, and together they consistently "win their hour", which means they attract more viewers than the shows in the same slot Oil rival nelworks CBS and ABC. As if this index of commerciai success - allied to an appreciative press - wasn't enough, earlier this year the star of The Office, Steve Carell - he plays Michael Scott, boss of the Dunder Mifflin paper supply company in Scranton, Pennsylvania - walked off with a Golden Globe for best TV actor in a comedy series.

Gervais already has two Globes for his perfomance in what is ostensibly the same role, which American viewers can see repeated on BSC America. In other words, he has three separate shows running on three separate stations in the States. He even goes so far as to describe himself and Merchant as "media and industry darlings" in the States: "I don't want to give you the impression that I get mobbed out there, but my cachet in the industry is probably as good as anyone's."

As if to prove this, he is preparing for a seventh appearance on David Letteman's talk show, and looking forward, too, to guesting on The Daily Show wilh Jon Stewart. Gervais has been offered Oprah, which he'd love to do, and even the ludicrousiy camp love-in that is Inside The Actor's Studio, where famous faces lecture credulous students on the finer points of thespianism. He's also considering some stand-up dates in New York, LA and Chicago. His ambition, he says, is to play Manhattan's Carnegie Hall.

Meanwhile, For Your Consideration is scheduled for a September release in America. Gervais plays Martin Gibb of Sunfish Classics, a small film company convulsed by a rLlmour that one of the three stars of its new film, Home For Purim, may be nominated for an award.

Gervais describes being approached by Christopher Guest to act in it as "like getting a call from God, saying, 'Do you want to look round heaven?'" This, it should be noted, is a God who just the other day sent Gervais a pair of shoes in a size too small for him, "because we decided that was the worst present you could buy anyone. I can't believe he actually went out and got them."

"The main thing," he says of his success, "is not to blow it." And the way you do that, above activity excepted, is by turning things down. Once you're in his position, he feels, it's really what you don't do that counts.

In early January; Ricky Gervais went to the cinema to see King Kong. Of the other movies trailed that day; he'd been offered and turned down parts in two. The first was The Da Vinci Code, Ron Howard's adaptation of Dan Brown's phenomenal bestseller, starring Tom Hanks. The second was Mission: Impossible 3, the latest commercial juggernaut from Tom Cruise.

Sitting there in the dark, he says he felt no ache of regret at missing out on these opportunities. "I thought, 'They look brilliant:" he says of the films, "but at no point did I go, 'I should have taken that: Because it's not what I do. I don't like doing The Office and Extras because I like watching myself on telly. I like coming up with the idea and unleashing it on the world. So someone putting me in a harness against a blue screen ... I don't know why that's good."

How about the money? 'Ive never regretted turning money down," he says. "I don't do anything for the money. It bores me.

"When I first started this job," he continues, "I got offered a couple of corporates. I think the first was #4,000. Then The Office came out and it was up to #25,000. This is 40 minutes, bit of talk, hand out some awards. And I thought, 'I hate that. I don't want to do those: Then I thought about it some more: 'That's more than my dad used to earn in a year. Who am I to turn that down?' So I did a couple and I fucking hated it. It's demoralising. I'm a chimp in a suit for hire. That's no way to go. So I don't do it. Not because it's bad, but because I'm not proud of it.

"Maybe it's because I started late," he says (Gervais didn't become successful until his late thirties). "Maybe it's because the most important thing where I grew up was, you've got to work for your living."

Gervais is the son of a French-Canadian labourer and a dinner lady who met during a wartime blackout. The youngest of four brothers, he grew up in a three-bedroom house on a council estate in Reading. It's a modest background, by all accounts a very happy one, and it inculcated certain values.

"Don't take short cuts," he says. "And do you know what? Even if the short cut works, it's not as good. Acting for a living's already a fucking short cut. It's already embarrassing enough. To be an actor, earning thousands of times the money of someone working down a fucking mine, or a nurse, or someone who risks his life going to war, the least you can do is do the absolute best you can to try and sleep at night."

He is absolutely relentless on this point. Questions of integrity arise throughout our interview. The pursuit of quality; the avoidance of compromise, the maintenance of standards - "keeping your shoes clean", as he puts it these are concerns that exercise Gervais apparently daily; if not hourly. There are things he does, and things he doesn't do, and that's that. He describes himself and Merchant as "fundamentalist comedians" in that they refuse to go for the cheap laugh, the easy gag.

Dressing up, silly wigs, puns, pratfalls and what Gervais calls "pandering" - "begging the audience for a laugh" - all these are strictly forbidden. So are "unfeasibly good one-liners, characters coming in for one joke and leaving, coincidences, huge contrivances ... there are just so many don'ts," he says.

What I still don't quite follow is why Gervais can't allow himself to appear in a Hollywood blockbuster. Turns out it's the same reason he won't appear on the English TV shows he likes, like the BBe's QI and Have I Got News For You.

"I think you get given a pile of goodwill," he says, "and you use that up with exposure and I don't want to use it up on frivolous things:' To that end, he's been rejecting film roles since 2001, when The Office was first shown. 'And by turning everything down," he says, "it's ridiculous but I was getting offered lead roles. And my fee now, that I've never taken, is up to $2m! And I've never done a film. I couldn't have planned it better!"

He thinks for a moment, then concedes that he's probably blown it by taking the part in For Your Consideration. "Fuck," he adds.

Last year, an American alcohol company offered him a million pounds for a TV ad. "My agent said, 'I know you don't do adverts but I've just got to tell you, it's a million pounds for one day's filming: I thought about it. Of course I thought about it! And I thought, 'That's mad. A million pounds!' And then I thought, 'So what?' But they thought I was negotiating. The power of 'no' in Hollywood is so much stronger than 'yes'. They came back and offered two million." He turned them down.

"The thing people don't realise," he says, "is the money's obscene as it is. The Office made a lot of money. We sold four million DVDs. It sold to 80 countries. And I've already made more from being executive producer on the American version of The Office than I made for acting, writing and directing the English version. Because the money in America is fucking obscene."

So how much money, exactly, does he have? "I don't want to tell you," he says. "It's embarrassing." But he's a millionaire many times over, surely? "Well, yeah." He looks suitably sheepish. 'Tve come out in a sweat here."

Certainly, the trappings of great wealth are not evident at his HQ, just off Tottenham Court Road. Gervais' own office is barely decorated. There's a large red abstract painting on one wall, a New York cityscape on another and, next to the sofa, a man-sized cardboard cut-out of Homer Simpson. Other than that, this could easily be the workspace of an unusually tidy financial officer or a highly organised personnel director.

His top-floor flat is nearby, near University College London where he was a philosophy student and then, in his twenties, entertainment manager for the Student Union. It was at the university, 23 years ago, that he first met his girlfriend, Jane Fallon, now a successful TV producer. They've been together ever since.

He paints a very settled picture. "I think you know everything: I live with Jane and a cat called Colin and a salamander called Tel. I like to go home, watch Deal Or No Deal. I'm in my pyjamas by six. You know: we eat, we open a bottle of wine. We dread it when we have to go out."

Once every few weeks, Jane and he will accept an invitation to go to a restaurant, perhaps with Jonathan Ross and his wife Jane Goldman, or with David Baddiel or Simon Pegg or Martin Freeman or Karl Pilkington and their respective partners. Far from revelling in the showbiz glamour of these occasions, Gervais takes a resolutely pragmatic attitude to eating out. He tells a story about going to Heston Blumenthal's famous Fat Duck in Bray, Berkshire, with Ross and Goldman. He'd been told to expect the best restaurant in the world but, to him, the best restaurant in the world would be downstairs from his flat, would always know what he wants to eat and have it prepared and on the table ready for his arrival, and would allow him to leave still chewing, adding the bill to his tab.

In conclusion, "I've been working towards middle age my whole life."

Matt Groening, the creator of The Simpsons, arguably the most garlanded show in TV history, first saw the original version of The Office on a plane. He liked it so much he bought the series on DVD, and then a European DVD player on which to watch it.

After being introduced to Simpsons producer Al Jean at the 2004 Golden Globe awards, Gervais was invited to meet Groening and the writers of The Simpsons at their offices to discuss him writing and starring in an episode. He describes standing in a boardroom with Groening and Jean when a writer walked in. "He was a Jewish guy with curly hair and glasses," remembers Gervais. "He went, 'Hi, I hope you like white guys.' And then 21 more just like him walked in. It was hilarious!"

Gervais describes The Simpsons as "the greatest achievement of humankind since putting a man on the moon. Fuck me, it's good. It's so far above other comedy." He says his first meeting with the writers was "a lovefest of mutual back-slapping. It was really incredible. They actually quoted The Office to me." For the first and only time during our interview, Gervais sounds like a competition winner.

It was actually Jane, his girlfriend, who had the idea of Homer and Marge appearing on Wife Swap. In the resulting episode, which is called "Homer Simpson, This Is Your Wife", Gervais voices Charles, who shares a number of traits with David Brent, including a goatee and a boring office job. "His wife is this Harvard socialite who married beneath herself and insults him at every point," explains Gervais, "and they've got this kid who's a child prodigy. The wife goes to the Simpson family and thinks she's landed in caveman times, and I fall in love with Marge because she's the first woman who's been nice to me."

Gervais has also written a song for Marge, called "Lady", which he performs on the show. "It's a dreadful love song," he says. 'Tm so proud of it." The writing process was fairly easy: drafts flew back and forth from London to LA, suggestions were made, encouragement was given, and it all came together fairly quickly.

The read-through was more daunting. "I haven't been so nervous since the first time I opened the mic on XFM," says Gervais. "I remember thinking, 'I'm going to embarrass myself here.' There are people doing nine voices, interrupting themselves. The first ten minutes, it felt like I was following Bob Hope. Then I opened my mouth, sounded a bit like Brent, and they're all loving it! "It was fucking brilliant," he confesses. "I had a whale of a time.

At one point during our discussion of The Simpsons, I mention the different cultures in British and American TV, specifically how many more writers work on American sitcoms than their British counterparts. Their teams are so much bigger, aren't they? "Yes, and our teams aren't very good," he replies.

This is something of a constant refrain with Gervais, who is perpetually underwhelmed by British comedy. Here he is on British TV comedy writers: "They're always the same people. The same people write for I Love The Seventies as some new satirical show on BBC3. Hold on! Have we really only got ten people? "It's different in America," he continues. "They're ambitious, they're good, they're funny. They do stand-up, and by the time they're 31 they've got their own sitcom because they're good. You don't see many 40-year-old hack writers in America. They get fired if they're no good. It's like natural selection."

Here's Gervais on American TV dramas: "The Sopranos, 24, CSf, The Wire, bang! We've got nothing like that. Nothing! It's such a big gap. Oh, look, State Of Play got in there at the bottom! No. 93 in the top 100 shows ... "

And don't even get him started on the British film industry: "Who fucking cares, really?" He says he doesn't disdain his contemporaries in Britain, but don't expect to catch him sneaking into a show on the Little Britain tour: "I don't have a low opinion of anyone, really. I just feel it's not for me. It's going to sound terrible but I do feel that myself and Stephen [Merchant] have more in common with Larry David or Mitch Hurwitz, who writes Arrested Development, than with anyone here." Gervais even feels - not entirely without foundation, perhaps - that the notion of celebrity makes more sense in America. "Being famous in England is the worst thing to be," he says. "There's no way I could sit in England out in public smoking a cigar with shades on. I'd be asking for a lorry driver to gob on me. I couldn't do it. In America? Wouldn't think anything of it. "England is funny." he continues. "Comparing our celebrities to America's is like comparing Blackpool to Las Vegas. It's division two."

In fact, he seems to have a fairly scathing opinion of famous people wherever they lurk. 'Tm not being nasty." he says. "I don't think celebrities are lower than normal people. But for me to like someone they have to be nice or they have to earn my respect. Just because most of their autobiographies are going to be 'love me or I'll kill myself'. that's no reason to pretend to like them. They're irrelevant. The last thing I want to do is spend my time with people just because they're famous. And I don't."

Fame is a recurring theme in Gervais and Merchant's work. It affects the characters in The Office, who are being filmed for a documentary which, in the mind of at least one of their number, is likely to make them famous, and the characters in Extras, some of whom actually are famous, others who would like to be.

But that's not all the two shows have in common. "Extras," reckons Gervais, "has the same themes I've always explored: social faux pas, the minutiae of human behaviour, ego, pretension, desperation, vanity ... "

Gervais believes, too, that both The Office and Extras are satires. "The Office," he says, "is social satire. It's a comedy about comedy: I never said this at the time but I snuck in all my pet hates about comedy." These include "people whose highest level of sophistication is remembering a catchphrase and then shouting it across a pub" as well as people who do impressions, people who can't tell jokes and that old hobbyhorse: pandering.

"I can't stand to see comedians begging for the laugh," he says, not for the first time. "Fucking let it go. Jesus Christ! If you have to take your trousers down and run around like a chicken to get a laugh ... There's nothing more tragic: people who desperately want to be funny are automatically unfunny. The least funny thing on the planet is a clown. I've never laughed at a clown."

Extras satirises celebrity culture. If anything, its humour is crueller than that of its predecessor. If the comedy of embarrassment is the defining mode of the age, from Partridge to Peep Show, perhaps Extras is the movement's zenith (or nadir, depending on your proclivities), with its jokes about genocide and the disabled and racism and its ridiculing of Les Dennis and other apparently sad cases.

Is there anything Gervais wouldn't make a joke about? "Apart from a specific person who's had a tragedy;" he says, "nothing."

Does he worry that some people may find some of the humour in Extras in bad taste? "The comedy in Extras comes guilt-free," he insists. "You know that me and Stephen as the creators are liberal, educated people, who are anti-racist, non-homophobic, non-sexist."

I'd argue that you might know that, you might not, but Gervais has the bit between his teeth.

"You don't have to worry about it," he says. "This isn't a racist cabby or someone cutting your hair who says there are too many blacks in the country. The Office and Extras are right-on, PC comedy. We've tested it. It's safe."

He also constructs an elaborate and convincing ethical case for the episode in which Les Dennis was humiliated. I ask if anything similar might happen in series two. He swears me to secrecy on the only two stars he'll admit to having lined up already - one an icon of British pop music, the other a comedy institution - but says we can expect more of the same: global legends will stoop to mock their own vanities while local has-beens will collude in lampooning their own desperation. Further than that, he won't be drawn, largely because he really doesn't know yet. I wonder if Extras, for all its cleverness, will ever be beloved in quite the same way as The Office? "The answer," says Gervais, "is that it probably won't." He admits that what really touched audiences about The Office was the love story.

"The nicest thing people have said," he says, "is that we got the heart as well as the head. People tuned in for Brent but stayed watching for Tim and Dawn, and come the Christmas special no one was talking about Brent at all."

Still, he's confident that the relationship between Extras' Andy and Maggie, his calamitous friend - which is certainly an interesting and unusual one for TV; in that it's a platonic friendship between two heterosexual people of opposite sexes - will provide plenty of interest for series two. "Let's not forget," he says, "that the greatest love story ever told is between a boy and his alien. And ET's totally valid."

The fact is, I think, that consciously or not, he'd been preparing for The Office forever, which is why it remains his best work. Brent was a character - originally called "Seedy Boss" who he'd been performing for his friends in the pub for years before he'd ever considered a career in comedy. The Office, perhaps as a result, isn't just the best British sitcom of the decade, it's among the most affecting and invigorating works of fiction produced since the turn of the century. He could never have predicted its global success, and asking him not only to follow it but to top it as well is unfair and unrealistic. Not that he seems fazed by any of this. The American ambitions aside, there are plenty of other things he wants to try: there will be more podcasts; a new stand-up routine to follow Animals and Politics; a film co-written with Merchant.

There's an idea for a sitcom, too. Originally floated before Extras was decided upon, The Men At The Pru would be set in the Seventies in a provincial backwater - maybe Margate or somewhere equally removed from London's burgeoning permissive society - where a group of twenty- and thirtysomething wasters measure out their lives in beer mats and Sunday league fixture lists.

"It was going to be sort of our Billy Liar," says Gervais. "I love the idea of it. I can just see it: film it on HiS video so you can get that colour, make it look really retro ... "

And then he's off again, doing what he loves to do, which is rabbit away about comedy, even comedy that may never be made.

"The single most important thing," Gervais says, introducing yet another theory; "possibly even more important than belly laughs, is empathy. Empathy is the most important thing in life. It's the point of life. So many people forget that..."

He pauses for a second. "I love this job."

Homer Simpson, This Is Your Wife will be shown on Sunday 23 April on Sky One.





Sign up now and you'll have full access to the site and get the odd email from Ricky when he's got something to tell you.

" ."sign up | forgotten your password?

Already signed up? Sign in here...

username:value("user")."\">".$form->error("user")."
password:value("pass")."\">".$form->error("pass")."

Hello, " .$session->username .". You're signed in.

" ."username\">my details | " ."edit details"; if($session->isAdmin()){ $toptagline = $toptagline." | admin"; } $toptagline = $toptagline." | sign off
".$form->num_errors." error(s) found