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

So who's funnier, you or Little Britain?

Erm... them. Can you ... put down that I like Matt Lucas but don't find that tall guy very funny. It will kill him. Williams? Walliams? Lucas needs to cut him out he's dead wood. I think Matt Lucas has the funniest face and body in Britain. Oh, except for Dr Fox.

He prefers to be called Neil Fox...

Yeah. Sorry. Neil Fox. He came to one of my shows, and I did the annoying thing of saying, "You're not a real doctor are you?" Apparently he is. He did a medical degree, but chose radio over medicine. So I said, "Oh, you might be able to help me then, I've got a bit of a sore throat." He had a look, and went, "I can't tell you what's wrong now, I'll have to take a sample, but I don't have a swab." So I go, "Don't worry, you don't need one. Do you know what the best swab in the world is? The human penis." He liked it. He's a good sport. You'd have to be.

You're here flogging not one but two DVDs. Surely you're too rich for more of our readers' cash?

It's not about the money. All I've ever wanted is a decent place to live and some pizza. I don't do corporates for 30,000 for ten minutes any more. I go and do stand-up in a pub for nothing instead. I just want to feed my soul now. Money honestly bores me. It's nothing to me. I hate being famous, too.

Why don't you back off and become a writer then?

That's what I'm going to do. Soon, I'll just back off and become a behind-the-scenes bloke. Saying that, I might be living in the jungle saving chimps. Whatever makes me happy.

Last time we met, you told us you were making some crap called Men At The Pru. Why would you lie to us, Ricky?

Erm, ah, no, no, that was, erm, true. We were making that, it's just we've got involved in this thing called Extras instead. It's not entirely dead, it might still happen one day. But it's all about our new series called Extras now. We'll hopefully film it around Christmas, and get it out in the New Year.

Are you nervous that it'll be shit?

Not at all. We did what we thought was right for The Office. We didn't water it down for the second series or the Christmas specials. And we're doing the same again. We never compromise - we work all day if we have to.

How much would it cost us to get a part as an extra in Extras?

No. You can't be in it. Can you imagine it, there'll be this scene in the green room, and everyone's sat around reading FHM. "Bloody good read this, so much better than GQ."

On top of crushing our dreams, you've been publicly mocking Nelson Mandela. Why are you so mean?

I don't really take the piss out of him. I just say that he was incarcerated for 25 years, and it proves the system works as he's gone straight since coming out. It's not taking the piss out of Mandela, it's laughing at my confusion.

So if you had a similar gag about kiddy fiddling, you'd tell it?

Yeah, this is funny... I talk about Live Aid in my show. Money for a drought? I'll give you a drought - the long hot summer of 1976, we had a hose pipe ban in Reading. There was a government advert telling us to bath with a friend. Which I did, well, I say a friend, he was more of a friend of my Grandad. He was a funny old man, full of tricks. He used to put a top hat on his lap, and let us put our hands in to feel the magic rabbit. He had no fur or ears. I made it sick once.

Are the memories of your brawl with Grant Bovey still painful?

It was a brawl, wasn't it? Not remotely a fight -like two old drunks. There was no sport involved. I'd learnt all these techniques, but it was all out of the window after one hit. Then it was just arms flapping about. The worst experience of my life.

The worst experience of your life?

No word of a lie. It hurt. Halfway through it, I realised I'd been very silly - people kept hitting my face. It was a good job I was 40 and already ugly. Do you want a fight now? Have you done boxing before? How old are you? How much do you weigh?

No. Twenty-four. Twelve stone(ish).

Erm, well, if we were to fight, I think that I'd have to do it in the first round. I'd have to win by knock-out or your stamina would do me.

We'll move on. Ever miss being a traffic warden?

No, because I never was. People always ask me and I have no idea where this came from. Apparently I was also a pizza delivery man. I think some lazy journalist just made it up because my interview was dull.

What, yawn, can we make up, then?

Well, I was a shark hunter for many years, you could put that in. It was tough. The other shark hunters would use protective cages, and harpoons, but I just went down in my Speedos with a dagger between my teeth - "the pirate way" we used to call it. I started off just hunting small fish and frogs, but then I went to Bognor, swam out about six miles, found a Great White, and was just hooked. Very good. Hooked? Oh yeah. I'm funny.

You slag off Ben Elton on your DVD...

No, no, I don't slate him really. I have a joke about him, but it's more about laughing at Ghandi.

...well we're doing a Ben Elton-style musical on the life of Billy Ocean. Are you interested in contributing?

I wouldn't consider it at all. The last thing this world needs is another musical. I mean Queen the musical? Surely Queen's the musical of Queen. Abba the musical? It's already music! Sorry, the same goes for Billy Ocean. But the musical of Anne Frank, now that I would be interested in.

The set design wouldn't cost much...

Yeah, but all the songs would have to be sung very quietly. "Ssshh, keep that trumpet down, the Nazis are just downstairs, you idiot."

When you're hanging with Jonathan Ross, do you constantly peek at his wife's cracking guns?

No, I end up looking at his knob, because he always fucking gets it out.

How would you rate Ross's pecker?

He's very proud of it. It is a good one. Maybe had some kind of extensioning done. I'm not sure if he's circumcised, I didn't look at the details.

Who's the most famous person you've taken a tinkle next to?

What kind of question is that? What is this? FHMs Celebrity Piss Section? We asked Jonathan Aitken about his toilet friends... "Well, FHM, I remember once, I was taking a wee aside Peter Ustinov, he was gushing out like a fucking rhino. I was trying to keep up, but Ustinov's fantastic urination technique was clearly leaving me behind." I don't know! I can't remember pissing next to anyone!

Okay! Do you find weird stalkers looking at your pee-pee when tinkling in public loos?

No! Some fans are a bit odd. I've had a few dressing up as me, sitting in my flat when I get home. I tell them to get out and they go, "No! I'm Ricky Gervais! You get out of my flat!" No you're not, you're not fat enough.

On your Animals tour you talked about gay dolphins. We were brushed up against by a seal once...

What? The singer with the scars? He's always doing that. He rubbed up against me at the Baftas, and I was like, "Seal, will you fuck off and make a record with Trevor Horn, because I will not stand this level of abuse any longer. I will not! Do you hear me?"

When you're 60 and churning out "last ever... we promise The Office Christmas specials", do you want us I to put you down?

Definitely not. It won't happen - I'll be I working with the chimps, won't I?

Can we go home now?

That's it? Sorry, you've got to transcribe all my crap ranting now. I'm sorry - I'm kind of disappointed with myself. "I'd have to knock you out in the first round"? I now realise it was a joke question. There I was measuring up your weight and height. You idiot, Gervais! Can we start over?

Interview by Lee Coan.

Politics is out on DVD on November 15, The Office: The Christmas Specials is out now on DVD.

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