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


From the News Of The World...

Ricky Gervais, the comedy genius behind The Office, Extras and a record-breaking string of hilarious podcasts - whose third book in the Flanimals series is out now - answers your questions.




Dear Ricky

You've worked with David Bowie, Samuel l Jackson, Jonathon Ross, Kate Winslet, Homer Simpson and Robert de Niro. Is there anyone you'd still love to work with - and has anyone turned you down?
Glen Hannah from Wolverhampton, and Jane Baker from Newark Notts

Ricky Says

There are loads of people I'd love to work with. Al, Jack, Clint, Quentin, and anyone else who's such a legend that I don't need to give a surname.
And yes someone did turn us down. Keith Harris. Orville was well up for it but Keith didn't think it was quite for him. (See I didn't need to mention Orville's surname.)


Dear Ricky

The last series of extras was fantastic! will there be any more or will you kill it dead after 2 series like the office?
Steve Croucher, Gosport.

Ricky Says

That's probably the end of Extras I'm afraid. Series two starts in The States on January 14th and the DVD comes out next spring. See it never really ends. We put so much into a series that we exhaust our ideas quite quickly.

We don't like to milk a project or exploit something we've created. We were offered a world tour of The Office stage show. Milking it.

We were offered a huge deal to put out a Brent doll like the one of Ray in Extras. We just think it detracts from the legacy. Also the brilliant Steve Carrell is making more money than any tour could and I don't need to get up off the sofa. Come on Carrell don't stop now.


Dear Ricky

You genius b****rd, were you surprised at how much of a hit the Office was in America?
Scott Holmess@msn.com

Ricky Says

Genius b****rd? That's how I want the Queen to address me when I get my Knighthood. Arise you genius b****rd.

I was surprised at how much The Office was a hit in Britain, never mind America. Apparently it's the most successful British comedy export of all time.(But still no knighthood). It's shown in over 80 countries and it's sold 4 million DVD's. (Not even an OBE)

On a serious note I must just say how brilliant I think the American Version is.

It's on ITV2 at the moment and on it's 50th episode in the States. We've actually written an episode for season 3 called The Convict. It looks like it's going to get syndicated and if that happens I'm going to buy Buckingham Palace and turn it into a huge Nandos. (She'll wish she'd got the sword out then.)


Dear Ricky

If you hadn't been a DJ, comedy writer, actor, broadcaster, podcaster, former pop star and best-selling children's author... what would you have done with your life?
Bronwen O'Brien, Kenilworth, Warwickshire

Ricky Says

Dear Bronwen,

I'd do what every person who can't write or direct or act does. I'd become a critic.


Dear Ricky

What settlement did you make with Brainpool, the producers of the blatant German copy of The Office ("Stromberg")? Did they get away with just putting a brief "Inspired by The Office by Gervais and Merchant" in the closing credits (from Series 2 onwards) or was there an additional financial settlement?

As a Brit resident in Germany, I have never seen such blatant plagiarism. Ralf Husmann still acts as if he is some kind of genius for "creating" the series.
Huw Davies, Nuremberg, GERMANY

Ricky Says

I can't go into details but yes there was an agreement reached and we are very happy with it. I must say I was very surprised when I saw the new unauthorised version. It's not like the Germans to just march in and take something that isn't theirs.


Dear Ricky

I love your podcasts but its obvious that Karl Pilkington is the real genius behind the shows. Have you got any plans to put him in a TV series - or are you worried that he would steal the limelight!?
Terry Wade, Shropshire.

Ricky Says

You are absolutely right.

Karl is the funniest man I have ever met. You can ask him a question on anything and the answer will never disappoint.

Everywhere I go people ask me "Is Karl real?". I'm afraid so. He went into hospital recently and had to fill in one of those forms where you give permission for your organs to be used after you die. He ticked heart, liver, kidneys but wouldn't tick "eyes" I asked him why. He said "Because I'd hate to be a blind ghost" Unbelievable. The book (The World of Karl Pilkington) is hilarious. As for putting him in a TV show I don't think he needs my help. He's working on something for channel 4 in which he, in his own words, "investigates stuff an' that"




Dear Ricky

You've done TV, movies, podcasts, radio, books and the Simpsons. What is your proudest achievement and do you have anything left to achieve?
Lucy Brooks, Windsor.

Ricky Says

I'm more proud of creating things than of the success that follows. I honestly wouldn't have been less proud of the Office if it hadn't got good rating or awards or whatever.

But in terms of proudest moments probably the Golden Globes or The Emmy. (The real Emmy- not the international Emmy. I've won one of those too but I don't talk about. Loads of Brits have got one of those) I do get an enormous buzz when people who I respect like Matt Groening or John Cleese, say they like my work. But as I say my proudest achievement is actually writing and directing The Office or Extras.


Dear Ricky

Please please ask this to Ricky, I'm a massive fan and read loads of interviews with him with the hope to find this out! Do you watch the excellent TV show Lost and if so did you see the episode where they mentioned a paper company in Slough as a shout out to the office?
Anna Harrison, Isle Of Wight

Ricky Says

I was chuffed when I heard the mention in Lost. JJAbrams who created the show is a fan of The Office and slipped in a little reference for fun. We are actually planning to work together but can't say too much about that yet.

He created Alias too, in which I did a guest appearance. I played an English terrorist and they dressed me in a big jumper and cords. Everyone one else was in Armani gear. I looked like Giles Brandreth wondering around a fashion show. JJ also offered me a part in Mission Impossible III but I was doing another film.


Dear Ricky

I hope you're taking your vitamins and looking after yourself, we want you to be around a LONG time to give us more brilliant laughs. Question: Will you be coming to Canada soon, and is it true you're doing a Canadian version of the show?

Thanks, Tara ps. I hear you are half-Canadian

Ricky Says

I am indeed taking vitamins Tara. It's so much quicker than just eating food that's good for you.

I was in Vancouver earlier in the year doing a film with Ben Stiller called A Night At The Museum. There is a Canadian version of The Office in the pipe line. It's actually a French-Canadian version called La Job.

And yes my Dad was Canadian and half of my family most of whom I've never met are dotted around Ontario.


Dear Ricky

We know what you think of Lenny Henry but which comedians do you rate? What is your favourite tv show?
Thanh, London

Ricky Says

I'm sure Lenny saw the funny side of it. He's one of the biggest and most popular comedians in Britain. I doubt he's bothered by a bit of ribbing from a fat bloke from Reading.

To answer your question. Most of my favourite comedy is coming out of America. Curb your Enthusiasm, Arrested Development, The Daily Show. The only British thing that I was really blown away by in the last few years was Peep Show. Also The Mitchell and Webb show was the best sketch show since Big Train.


Dear Ricky

I am a huge fan of you and steve merchant and would love to write my own comedy. I am 16 years old and have started a 2 year media production course at college. Is there any advice you could give me to help me progress in the world of comedy??
Sam

Ricky Says

Firstly there's no rush. You're 16. Purposely plan on taking at least ten years to make it. Secondly write about what you know. What can you give the world that's peculiar to you?. There's no point in doing stuff that anyone can do. Be original. Thirdly, don't do anything just for the money or the exposure. Do things that you'll be proud of. It's worth more than success and it lasts longer. And finally don't wear wigs and funny glasses and shout "Are you ďavin a laugh?"


Dear Ricky

hi ricky can u send me a copy of extras sires one plz?
jordan ward, north yorkshire

Ricky Says

Dear Jordan

I think you used some unnecessary letters in your question. You could lose the E in extras. Xtras. See. Also instead of going to all the trouble of writing out "one," which is a mad waste of time, why not try 1.

Thanx 4 ur txt tho. Xtras dvd sires 1 on way.

Our thanks to Ricky Gervais. Who is brilliant. Fact. For more laughs, go to Ricky's homepage.




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