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"; ?>

The most remarkable thing about Ricky Gervais is how remarkably similar he looks off screen to how he looks on it. Television doesn't alter him, and doesn't seem to add 10 pounds like it's supposed to. He appears untouched by wealth, fame and, most markedly, fashion: here is a man styled by JD Sports, wearing a black T-shirt, Adidas tracksuit bottoms and white running shoes. Ring the bell to his small second floor office, off Tottenham Court Road in London and it's him that answers and buzzes you in. There is no secretary, security or PR It's both unusual and oddly impressive.

This, though, is how he likes it. His office, aside from a British Comedy Award perched discreetly on a shelf next to a box file, holds few clues to the incredibly successful entertainer who inhabits it. Aside from an iMac and a desk there's barely anything in the room. On one wall there's a Comic Relief calendar of The Office stuck on July with a picture of Keith glumly looking out. One suspects he hasn't turned over to August not through laziness, but because it displays a picture of himself. As he says "I get no joy whatsoever seeing my fat face on telly". He sees his work, alone and with writing partner Stephen Merchant, as a cottage industry - they do stuff, the BBC, HBO or whoever have little choice but to accept it the way he presents it to them. Total control.

"The analogy I use is it's like getting an Airfix kit and getting someone else to do it for you. Where's the fun in that?"

This philosophy to his work extends to the podcasts he records here with Merchant and their friend Karl Pilkington - former producer of their Xfm radio shows turned Mancunian pub philosopher, internet icon and living example of what the world would be like if the only reading matter available was the Fortean Times.

The podcasts - 30 minute broadcasts the internet-savvy can download to their iPods - were launched by the Guardian in December 2005 and begin a third series via iTunes next week. They've been enormously successful with over half a million downloads an episode.

"It's one of the most exciting things I do." he says. "It's mainly down to Karl."

When they first met at Xfm Karl was just the man who pressed the buttons and cued the records - Ricky and Stephen were far too important to do that.

"He just piped up one day and that was it, we discovered him and we got lazy. First of all we'd write stuff, we'd riff, we'd work quite hard, play records we loved and then after a year we were just 'Karl, what do you think of this?'... and he just never ran out."

Even the mention of Karl's name starts Ricky Gervais giggling. At one point he breaks from the interview to consult his favourite website, Pilkipedia - an online encyclopaedia dedicated to his friend - and begins reading out, between fits of high pitched laughter, facts and quotes about his mate such as "He learned at school that Jaffa Cakes go some way to curing cancer." And "Jellyfish are 97% water. We should give them another 3% and make them water. It angers me."

Of late, claims Ricky, Karl has become completely obsessed with insects and has taken to following ants and ladybirds, which he has discovered are right-handed.

In the podcasts it is merely Ricky and Steve's job to prod and guide Karl into revealing his thoughts and opinions, as well as reading spectacularly mundane entries from Pilkington's diary - a book that differs little from those written by 12-year-olds in that it invariably mentions what he ate for tea.

"He's amazing," says Ricky. "The things he says about his childhood that he thinks are normal. Like there were two kids with big heads and webbed feet at his school and I went 'Were they related?' And he said 'No'. I went, 'did they knock around together?' And he said 'no - that'd be too obvious'. And his philosophies... "

Gervais describes Karl's thoughts as a bottomless pit of comedy jewels but he's wary of exploiting him - "I don't want to over-fish".

"He's a mate first of all, though. I should probably stop talking about him as if he's a discovery I've thawed out of ice and shaved and took to college like some bad American teen movie. My main worry is that hell bump his head one day and become clever."

Ricky calls him at least twice a day. Recently their conversation was cut short because Karl had to deal with a giant wasp. Later it emerged that he had witnessed a bumblebee having a heart attack.

"I said, 'How do you know?' He said 'Well, it was overweight'."

The podcasts aside it's a busy time for Gervais Industries. There's an episode of the American version of The Office to write while Canada have just started their own version of the hit show renaming the lead character David Gervais ("it's a French-Canadian name"). Meanwhile he and Merchant are toying with making a drama series although if it's not as good as The West Wing they see no point doing it. He's also just finished filming the second series of Extras, which returns to BBC2 next month and again features an array of A-list stars including Daniel Radcliffe, David Bowie and Orlando Bloom signing up to mock themselves. This time the show follows Ricky's character, Andy Millman, enjoying success in a storyline that sees him taking the almost exact opposite career trajectory to Gervais. In the show Millman's sitcom is made but he waters it down so it becomes lowest common denominator TV. He becomes famous, goes on chat shows, does a bad play and hangs out in private clubs attempting to ingratiate himself in the showbiz industry. Ricky could have easily have chosen a similar path, he resisted overtures to air The Office on BBCI and consistently turns down silly money offers for action movies better suited to Bruce Willis and satirical quiz shows better suited to Dave Gorman.

"Secretly I think I'd be quite good on QI," he admits. "But you have to discipline yourself and you have to ration yourself. I can get sick of someone I like within the space of a weekend if I see them on two quiz shows and then in the Sunday paper. I've never regretted saying no or turning anything down."

What he hasn't turned down is a run of three cameo film roles, one in Spinal Tap creator Christopher Guest's Hollywood spoof For Your Consideration, in Ben Stiller's new film ("he emailed me and wrote 'Would you like to return the favour? No pressure'.") and just a couple of weeks ago acting opposite Robert De Niro in Stardust as, he says, "a sort of Never Never Land Arthur Daley". Of the latter he describes being cool and casual initially before crumbling after eight hours into a fan boy at De Niro's feet and telling him "you're the greatest actor in the world. I love you".

"It's like winning a competition," he says "It's like would you like to play with Spinal Tap for a day? Yes. Would you like to play with The Godfather for a day? Yes."

Does he ever feel like he's getting away with it somehow?

"No. I've certainly got away without a backlash for a long time. I don't know why that hasn't happened."

Like an idiot I suggest that perhaps it's because everything he's done has been good.

"That's all you need to do. It's as simple as that," he chuckles, blurring into David Brent for a second. "Advice, yeah. All you have to do is do nothing wrong."

The third series of The Ricky Gervais Show podcasts starts on Monday 21 available on iTunes. Extras begins September 14 on BBC2

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...


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