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

"IT'S QUITE EASY doing David Brent, really," says Ricky Gervais, steepling his fingers together and cocking his head to one side. "He thinks everything he says is philosophy," he continues, his voice changing timbre to the descending pitch of the middle-management "chilled-out entertainer". "Like he's handing down wisdom." The effect is completed when his front teeth come to rest over his bottom lip. "The white-man overbite."

It's a subtle but pronounced transformation, one that will no longer be seen outside of repeats of The Office. "Absolutely. It's all over," he confirms. Apart from picking up awards-including two Golden Globes-for the excruciatingly brilliant comedy series, Gervais has not been idle. He has completed two stand-up comedy tours, Animals and Politics - the latter will appear as a DVD this month - written a children's book, Flanimals, and is currently working on Extras, another observational comedy, with his writing partner Stephen Merchant.

Perhaps due to this demanding schedule, his central London office is in some disarray, despite the fact that he had been based there since January. A framed disc commemorating 150 copies sold of David Brent's If You Don't Know Me By Now sits propped against the wall in the corner.

Gervais takes a seat, ready to field your questions. "Do I have to answer them if they're horrible?" Of course. "Well, just cut out the waffle and make me look articulate, will you?"

Have you had any feedback about The Office from the Slough tourist board? Lloyd Davis, Oxford
Apparently they wrote to the BBC after the first series went out. I can't remember exactly what they said, but the gist of it was that they wanted us to know that Slough's changed. I don't know what they expected, whether they wanted David Brent to look out of the window and say, "I love the new pedestrianisation of the city centre, it's great for shopping, isn't it? Anyway, Gareth..." Why Slough? Apart from it being onomatopoeic - Slooough - we wanted somewhere very ordinary and unglamorous. Not that I know, I've only been there once when I was a kid. It probably has changed.

You were recently voted one of the men who women -including me - secretly fancy. Who do you secretly fancy? Annie Hyatt, Woodley
The thing about that is... it's not a compliment at all. Who do you fancy but would never admit to it? I don't secretly fancy anyone. I had a friend who fancied Cheetara from the Thundercats. Someone else said, "Oh, I know what he means, I fancy the woman in Roger Rabbit. "Actually, I quite fancy Soo, the panda off Sooty And Sweep, although I think she was pregnant at one point so she's probably not available. How did that happen? Real pandas don't get pregnant.

Do you know any jokes? Vie Smith, Bristol
I know lots of jokes, I don't tell them, really. Why has Noddy got a bell on his hat? Because he's a cunt.

Do you ever wear the "Sergio Georgini" jacket from The Office? David Hillier, email
No. I think that went for about seven grand at an auction. I heard that Ian Wright phoned up and said, "I want to buy it." I don't know if he got it - it was either the jacket or the shoes, he wanted one of them certainly. I assume as a joke.

Has your philosophy degree proved useful in your career? Laura Harris, Chepstow
There was actually a bit that one of my tutors came up with, that we put into The Office. There are three things important to a good life - a decent relationship, a decent job of work and making a difference. Talking philosophy, it hurts. You know the thing about how chimps with typewriters will eventually write the complete works of Shakespeare to show the nature of infinity? My friend Karl couldn't get that. He was going, "What if they got one word wrong?" I said, "They would, but they'd do it an infinite amount of times." He went, "Bollocks, is it the same chimp? I could see if it was one chimp because he'd remember what he was doing." At one point he asked, "What shift pattern is he on?"

Did you really beat Grant Bovey on points in that celebrity boxing match, or did you get the nod because everyone thinks he's a twat? Doug Shearer, Sale
That was weird. The press tried to make out it was a grudge match, but I'd never met the bloke and I certainly have got nothing against him. They had to have a hero and villain and they decided how that was going to be carved up. I think I won on points because I leant on him heavier than he leant on me. I wouldn't fight again, it's the hardest thing I've ever done. Considering I don't do anything else - panel shows or game shows - I just chose the worst one I could ever do apart from I'm A Celebrity Get Me Back On Telly I'll Eat A Spider. Christ knows what I was thinking. Could I beat David Brent in a fight? Yeah. I'm meaner than him. He's quite a nice person deep down.

If the money was right, would you do "The Dance" at my hen night? Jennifer Barker, Fallon, USA
I couldn't do it if I wanted to. It does actually make me laugh when I see it, but mainly because I can't remember doing it. I just went berserk for a couple of minutes. I can't remember getting that low, I didn't realise I looked like an orang-utan, I've got this pot belly, these ridiculous arms flailing and little short legs and I think if I did it now I'd break.

I hear you've got a 60-inch TV set in your home. Isn't that a little excessive? Donald Towerhill, via email
I haven't. Where did they hear that? I've got quite a big TV, but I think it's only about 48 inches. I'm not that materialistic, really. As you can see, I don't spend a lot on clothes. Is there anything I always wanted to buy? No, everything I wanted as a kid, by the time I could afford it, I was 40. So, unless you're Tom Hanks in Big or Jonathan Ross, you grow out of those things before you get enough money. I pay for an easy life-peace and quiet. Like Bryan Adams. Didn't he buy the pub next door to him and close it? That's what money's for.

What's the ringtone on your phone? Is it Handbags And Gladrags? Rob Smith, via email
No, it's the Dom Joly one [the Nokia tone of Trigger Happy TV fame]. I'm such a technophobe I wouldn't know how to change it.

How much did you get for appearing in the Alias TV show? Pete Samuels, Brighton
Not much. I did that because I know [Alias creator] JJ Abrams and he's a big fan of The Office. He'd written a part especially for me, so I thought I'd just dip my toe in the water. I played a bad psycho terrorist. I laughed for the first two days because I couldn't take the serious faces. Did I get beaten up by Sydney [Jennifer Garner]? I got killed by her dad and brought back to life. He'd strangled me, I'm laying on the floor, Sydney comes in and goes, "What have you done?" His line was, "Get the defibrillator" and I fucking cracked every time.

When you worked with Bullseye star Tony "Listen to Tony" Green on your chat show, Meet Ricky Gervais, did you ever play darts with him? Steve Edwards, Banbury
No, he just told me funny stories about working on Bullseye. There was one about the bloke who only had to score 1 - they were on 99 - to win the big prize and just showing off he went down on one knee to throw and it hit the board and came out. Was it for a speedboat? Maybe when they lost. I think they had two curtains, like, "They've won, get the garden furniture out."

Where did those Seona Dancing [Gervais's hugely unsuccessful early- '80s new romantic duo] cheekbones get to? ZoeAndrews,Readmg
Well, that's 20 years of eating cheese. I'm not actually storing it like a hamster, it's cheese I've converted into fat and I've put it under my skin. Do I still get royalty cheques? A few pence from a couple of plays in the Philippines now and then. I can't retire on that.

If David Brent came to you for advice on getting women into bed, what would you say? Philip Moore, London
I'd say, "Don't try so hard, don't talk about yourself so much and whatever you do don't dance with her."

What do people shout out at you most often? Alan Kerr, Bidford-on-Avon
They don't shout really. I'm getting a better class of viewer, they're very polite. It's either "Alright, mate?", "I love the show," or "You look fatter in real life." On The Jonathan Ross Show, Jonathan asked that question, and I was saying, "Well, he hasn't really got a catchphrase, that's sort of the point of the show, that he hasn't really got his own identity." As we came out afterwards, a bloke ran up to me in the car park and went [does a quick burst of The Dance) and ran away.

What do you think of the Bo'Selecta impression of you? It makes you look quite egotistical. Adam Hett, Saltney
I think it's good, it looks more like Ricky Tomlinson but I take it on the chin, like a man. A fat bloke in boxing gloves. Perfect. Egotistical? The thing is, what people don't realise is that's an in-joke because the producer who co-writes it worked with me on Meet Ricky Gervais. Whenever we used to go out and I got asked for an autograph he used to go, "Ooooh! Ten gold stars!" I actually hate being recognised.

If you were a politician what laws would you change? Tim Larkin, London
Teach evolution and science as fact and religion as fiction. There, that'll do. Does my Politics tour have any serious message? No. Also, comedians with a cause? Fuck off, just be funny. I don't think that there's a place for worthy campaigning in comedy. So it's not like Ben Elton? No, he's mentioned, though. In a nice way? Not really.

Did you give Suede that shit name? Tom Davenport, Burbage
No. I didn't give Suede much at all. I only managed them for a little while [when he was Entertainments Officer for the University of London Students' Union) and the only thing I did was send their demo tape off to Nude records. It's one of those things you dabble in. I think every Ents manager in Britain at the time had a couple of bands they were trying to break. I quite like the name.

Now you're rich, are you going to get your teeth done? Matt Goold, Stapleford
I actually interviewed David Bowie and I said, "When Iwas 14, 15 and my teeth came through like some sort of mad witch, my only consolation was that I had the same teeth as you and then you got yours fixed. Do you feel guilty?" He said, "Not a jot." I'm not going to get them fixed, no.

Are you pleased for fellow 11 O'Clock Show star Ali G or do you dislike him intensely? Joel Sawyer, Cheshire
Sacha? I like him. At the time he was the biggest thing in Britain and I was this little fat guy trying to start a career and he was always very nice to me. I was worried about taking over from Ali G. It was a tough act to follow, but it was my first TV job and I'd have been mad not to have a go.

You seem like a rock star trapped in a greengrocer's body. If you could be in any band ever which would it be? Ben Hartland, Liverpool
That's a difficult one. Thin Lizzy would have been great. Radiohead are my favourite band at the moment. They could put me at the back in the dark with a hat on and let me just make noises on the synth. I'd be happy with that.

Are David Brent and Ricky Gervais basically the same person? B Smith, London
Some lazy journalists have said that. You've got to ask yourself this; Could David Brent have written and directed a sitcom? I don't think so.





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