Results 1 to 6 of 6

Thread: Checking if a cookie is set in PHP

  1. #1

    Checking if a cookie is set in PHP

    Hey guys, I saw that a certain someone had left the board, so I considered it worth returning. Anyway, Im having problems with a site I do for a church. I want it to check if you have a cookie from them already, if so, say a specific greeting. If there is no cookie set, display a first timers welcome and then set the cookie. Here is what I have so far:

    Code:
    <?php
    $welcome= "Welcome to our Site! Thanks for coming!";
    $now=date("l dS of F Y");
    ?>
    
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <div align="center">
      <table width="97%" border="5" height="105" bgcolor="#FFFFCC">
        <tr> 
          <td height="91"> 
            <div align="center"><img src="../pics/name.gif" width="761" height="74" align="absmiddle"></div></td>
        </tr>
      </table>
      <table width="97%" border="5" cellspacing="0" cellpadding="0">
        <tr align="center" valign="middle" bgcolor="#FFFFCC"> 
          <td width="77"> <div align="center"><font color="#FFFFFF"><a href="index.php" target="_self">Home</a></font></div></td>
          <td width="119"> <div align="center"><font color="#FFFFFF" size="2"><a href="salvation.php" target="_self">Salvation</a></font></div></td>
          <td width="83"> <div align="center"><font color="#FFFFFF" size="2"><a href="vision.php" target="_self">Our 
              Vision</a></font></div></td>
          <td width="107"> <div align="center"><font color="#FFFFFF" size="2"><a href="about_us.php" target="_self">About 
              Us</a></font></div></td>
          <td width="147"> <div align="center"><font color="#FFFFFF" size="2"><a href="ministries.php" target="_self">Ministries</a></font></div></td>
          <td width="166"> <div align="center"><font color="#FFFFFF" size="2"><a href="missions_community.php" target="_self">Missions 
              & Community</a></font></div></td>
          <td width="148"> <div align="center"><font color="#FFFFFF" size="2"><a href="/calendar/" target="_top">Calendar</a></font></div></td>
          <td width="148"> <div align="center"><font color="#FFFFFF" size="2"><a href="http://www.mapquest.com/maps/map.adp...=Get+Map" target="_top">Location 
              & Directions</a></font></div></td>
          <td width="176"> <div align="center"><font color="#FFFFFF" size="2"><a href="prayerlist.php" target="_self">Prayer 
              Requests</a></font></div></td>
          <td width="11"><font color="#FFFFFF"> </font></td>
        </tr>
      </table>
      <table width="97%" height="42" border="5" cellpadding="0" cellspacing="0">
        <tr bgcolor="#FFFFCC"> 
          <td width="29%" height="32" border="5"> <div align="center"><font color="#0000CC" size="3">Church: 
              (228) 497-2373</font></div>
            <div align="center"><font size="2"><font color="#FFFFFF"><font size="3"></font></font></font></div></td>
          <td height="32" colspan="3" bgcolor="#FFFFCC"> <div align="center"><font color="#0000CC" size="3">Pastor: 
              Bro. Coy Rice</font></div>
            <div align="center"></div></td>
          <td width="36%" height="32" colspan="4"> <div align="center"><font color="#0000CC" size="3">2303 
              Callie Road </font></div></td>
        </tr>
      </table>
      <table width="97%" border="5" cellpadding="0" cellspacing="0" bgcolor="#FFFFCC">
        <tr> 
          <td height="34" align="center"> 
    <?
    if (isset($_COOKIE['NGBC_Cookie']))
    {
     
    Print " Welcome back! You last visited us on ";
    echo $_COOKIE["NGBC_Cookie"];
    }
    else
    {
    echo $welcome;
    setcookie("NGBC_Cookie", $now);
    }
    ?> </td>
        </tr>
      </table>
    </div>
    </body>
    </html>
    The php runs, but if I clear my cookies and then revisit the site, I get the same greeting. Any ideas?

  2. #2

    Re:Checking if a cookie is set in PHP

    Which browser are you using?

  3. #3

    Re:Checking if a cookie is set in PHP

    Testing it at work, so using IE6 for now.

  4. #4

    Re:Checking if a cookie is set in PHP

    [quote author=mountainman link=board=9;threadid=10160;start=0#msg91931 date=1105996752]
    Testing it at work, so using IE6 for now.
    [/quote]

    Try hitting "Refresh" after reaching the web page, post clearing the cookies. IE6 has this problem, where it simply looks in the cache for server-side generated dynamic web pages, instead of requesting a new content from the server. If this approach does work, you can try placing a (X)HTML
    Code:
    <meta http-equiv="refresh" content="0" />
    statement or a
    Code:
    header('refresh: 0; url=<URL>' );
    statement in PHP.

  5. #5

    Re:Checking if a cookie is set in PHP

    Hit ctl+f5 instead of just f5 for refreshes.

  6. #6

    Re:Checking if a cookie is set in PHP

    Thanks I think I got it working. Dont get much time to work with web stuff anymore, working 4 10 hours days at work, and taking 3 classes, as well as trying to spend time with family. Im tired just thinking about it.

Similar Threads

  1. Bandwidth Checking
    By pavangogineni in forum Linux - General Topics
    Replies: 9
    Last Post: 04-19-2006, 09:20 AM
  2. checking for a set cookie
    By wolfbrother in forum Linux - Software, Applications & Programming
    Replies: 1
    Last Post: 01-18-2005, 04:19 AM
  3. Checking stats
    By mcdougrs in forum Linux - Software, Applications & Programming
    Replies: 1
    Last Post: 10-24-2003, 06:21 AM
  4. bandwidth checking
    By in forum General Chat
    Replies: 3
    Last Post: 01-01-2003, 03:16 AM
  5. Replies: 3
    Last Post: 05-13-2002, 05:11 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •