Diving into PHP: Day 9

Starting with day 9, I’m going to begin teaching you some practical uses of PHP. Today, I’ll show you how to detect whether or not a user has visited your site previously. This operation can then be used to add a “welcome” box to your site – that typically encourages the user to sign up, via the RSS feed. It’s easier than you’d think!

Day 9: First-Time Visitors

Be sure to click on the “Full Screen Toggle”.

Download the Source Code


  • Really good, keep it up, i am enjoying learning php this way

  • Thanks again Jeff! :D You got to speed up between days, the wait is killing me :D

  • Jeffrey says:

    @Ed – Thanks! I wish I could do more. I just get so busy. I try to get at least two out each work week.

  • Joe says:


    It’s just a pleasure following you on this these screencasts. I just wanted to say thanks again for staying the course. Are you going to do anything on LDAP authentication? Thunderbird has become a favorite application cos of checking for RSS feeds from themeforest.

    God Bless man,


  • demogar says:

    Great tut AS USUAL!!!. I think that would be possible with the jQuery Cookie plugin too! Take a look at it (only for learning purpouses)


  • M.A.Yoosuf says:

    @jeff, in future do we have to pay for these to? :S. I’m completely disappointed with the new strategy of you guys. :@

  • George Hennessy says:

    @Jeff – I’m a brand new PHP programmer, I’ve watched all of your PHP videos and I think that they’re fantastic. I’ve learn a lot from watching them. But as a PHP newbie, I don’t fully understand how I would implement week 9’s lesson. I still think what you taught us was really cool, but I need help seeing the big picture and how I would implement this. Thanks Jeff. BTW, I would’nt mind buying video tutorials if they’re excellent.

  • Jeffrey says:

    @M.A. Yoosuf – Of course not. Why does everyone think this? If you don’t want to become a premium member, absolutely nothing will change. We’re simply offering more advanced tutorials for those that are willing to pay.

    Diving into PHP will always be free! …Just subscribe to the RSS feed for me. :)

  • Hi what is this diving in php??

  • Alex Hughes says:

    Another great addition. Thanks!

    Just wondering if there will be anything on using AJAX with PHP (possibly to update databases) in the series or if you know any resources which cover this?

    As atm, I am so pickled atm :- )

    Thanks again!

  • MoZi says:

    Very nice one ! Thanks
    would u please let me know good idea (technic) to enforce user to resubmit the form refresh the page, click twice to button
    using PHP ( if the handle the POST in same file or other file )

    Thanks in advance

  • Willabee says:

    I noticed you added your script blocks at the end of the page on this occasion, following YAHOO best practises. This means you can remove the onDOMReady code and just have:

    $(this).fadeOut(600, function() {

    because the the DOM will be ready (rendered) by the time your script runs. Another advantage of this technique.

  • Jeffrey says:

    @Willabee – Yep. You’re right! I mention that very thing somewhere in the screencast. :)

  • Mike says:

    Day 10 coming soon?

  • Marko says:

    Very cool series, Jeff. Thank you! :)

  • Shibs says:

    Hey Jeff. I’m a huge fan of this series.

    This example didn’t work for me in Safari. It seemed like the cookie wasn’t being set. Every time I refreshed it kept giving me the first-timer welcome. However I tested it in Firefox and it worked fine. Has anyone else had this issue??? Perhaps it’s because of my cookie settings in Safari.

    Anyway, thanks Jeff!

    - Shibs

  • Michael says:

    @Shibs, Ive had the same problem in firefox but as you meantioned I think its doe to the cookie settings.

    @Jeff, Awsome screencasts. I really learned alot from you! Keep up the great work!


  • Ingo says:

    Very nice Tutorials, i really enjoy learning php now.

  • Travis says:

    Hey Jeff, just wanted to stop in and say that these are by far – the best PHP tutorials for beginners that I’ve ever seen, plus they’re in screencast format no less, which is great.

    I did have one question though – I was trying to implement your “passing variables from 1 page to another” tutorial with this one. “Index.php” requires the user to input his/her name before continuing to the dummy text page. It either says “Welcome to the site Travis, have a look around” or if they’ve already been there – “Welcome back Travis”. That part works like a charm, the problem I’m having is if I close the page out and reopen the main.php (The file with all of the cookie PHP), I get an error about an Undefined Index. I’ve changed $_GET to $_POST so you can’t see it in the address bar, but does the cookie not save the $_POST variable and recall it if the user goes back to the site after closing the browser window? Any help would be much appreciated. Thanks so much in advance.

  • Arturo says:

    I am extremely thankful for these tutorials, they could not have come at a better time. I started a new position and our company is gearing towards web applications, these tutorials are helping me get a head start towards completing future tasks. Thank you.

  • Hey, I’m having a problem with the HereDoc at [time 7:00 - 8:00 minutes into the video]. When testing the site shows :

    Welcome to my site. Please take a look around and subscibe! EOT; setcookie(‘myCookie’, 1, time()*7*365); } else { $welcome = “Welcome back!”; } ?>

    My code is:
    if(!isset($_COOKIE['myCookie'])) {
    $welcome = <<<EOT

    Welcome to my site. Please take a look around and subscibe!


    setcookie(‘myCookie’, 1, time()*7*365);
    else {
    $welcome = “Welcome back!”;


    Anyone out there know whats wrong?

  • Zee says:

    i have some problem with out

    $(function() {
    $(‘#box’).click(function() {
    $(this).fadeOut(600, function() {



  • Zee says:

    second problem is cookies are not save in my explor

  • Steve T says:

    @ Kevin

    I had the same problem, turns out I was viewing my php file in the various web browsers through my file system, rather than via mamp (or wamp if you’re on windows).

    check your browsing to your file via http://localhost/... or whatever your local webserver address is, rather than file://volumes/…

    at least thats what I was doing wrong, and it sorted it for me.

  • Anon N says:

    If you are having problems setting the cookie, and you are using localhost and apache, here is the format that seems to work:

    setcookie(“username”, “George”, false, “/”, false);

    This was found on the following blog: of http://www.aeonity.com/frost/php-setcookie-localhost-apache

  • sharath says:


    Really nice tutorials…… thanks for all the tuts Jeff! :)

  • Kevin says:

    This is still the best way to learn PHP. Great job Jeff.