I want to call a pop up registration form from my home page. However, I only want it to be called just once so that I don't annoy visitors. How do I achieve this with PHP? I have tried to use cookies and an include call to the pop up but I am not getting anywhere; help please?

    You mean a popup window? That's client-side (i.e. javascript). PHP is server-side. Try a google search for window.open()

      Are you using logic like this?

      if (!$_COOKIE['ALREADY_DISPLAYED']) {
      set_cookie("ALREADY_DISPLAYED","1");
      // print html/JS code here to cause pop up window to appear
      }
      

      That should work.

      Are you placing that code at the very top of your PHP page? You can't set cookies after any text has been displayed on the page.

        Thank you Etully; that was just what I was trying to do.

          etully wrote:

          Are you using logic like this?

          if (!$_COOKIE['ALREADY_DISPLAYED']) {
          set_cookie("ALREADY_DISPLAYED","1");
          // print html/JS code here to cause pop up window to appear
          }
          

          That should work.

          Are you placing that code at the very top of your PHP page? You can't set cookies after any text has been displayed on the page.

          I want to use a hidden layer for the pop up so my question is can I use DHTML in the middle of the conditional if statement. i.e. before the end of the curly brackets so that it is a result of the conditional statement?

            I want to use a hidden layer for the pop up so my question is can I use DHTML in the middle of the conditional if statement. i.e. before the end of the curly brackets so that it is a result of the conditional statement?

            Yes. That's really the main point of PHP: You use it on the server side to dynamically construct something that will run on the client side. Sometimes you want the DHTML to be included in the web page - sometimes you don't. PHP lets you do that.

            For example, these are my main uses of PHP:

            1. Conditionally either show or not show certain text, HTML, Javascript, Ajax, or DHTML elements
            2. Use variables to change how certain text and HTML is written.
            3. Use conditions and variables to alter Javascript, Flash Embed Tags, and CSS so that it performs differently for different users and different conditions.

            It took me awhile to wrap my mind around item 3 but it's very powerful. You are using one language (PHP) on the server to write client side software (Javascript, Flash, or even possibly CSS) that performs in a certain way on the page - but not the same way everytime for everyone.

              How do I insert the Dhtml code into the PHP block?
              I keep getting a Syntax error so I feel I should be enclosing the DHTML code in some way?

              My code follows:

              <body class="thrColFixHdr">
              <!--Show pop up if not shown previously-->
              <?php
              if (!$_COOKIE['show']) {
              set_cookie("show","1");
              <div id="apDiv1">
              <div style="background-color:#FFCC66; border:dashed; border-color:#993333;" class="textCtr">
              <p class="textGreenCtr">Sign up now to our Marketing Property newsletter.</p>

               <p class="textGreenCtr">
                You will 
                receive marketing tips and information on<br />
                marketing property here in Thailand<br />
                to help you sell more homes!<br />
                Aimed at developers of all sizes<br />
                the range of topics covered includes; <br />
                marketing, sales, legal &amp; contractual advice, <br />
                property ownership  structures, tax planning, accounting, <br />
                business administration, company  formations, etc...</p>
              <p><a href="http://www.1st-choice-homes.com/newsletter/?p=subscribe&amp;id=2"><img name="freeTips" src="images/freeTips Org.gif" width="150" height="120" border="0" id="freeTips" alt="Marketing Property" /></a></p>
              <p>Receive a FREE report showing<br />
                you how to prepare<br />
                a full marketing plan<br />
              for your development! </p>
              <p class="smallCtr">[<a href="#" onclick="MM_effectAppearFade('apDiv1', 2000, 100, 0, false)">Close Window</a>]<br />
              </p>

              </div>
              </div>
              }
              ?>
              <!--End of pop up-->

              Error message:
              Parse error: syntax error, unexpected '<' in c:\wamp\www\htdocs\1st-choice-thailand\index.php on line 37

              Line 37 = <div id="apDiv1"> above

              Thanks for your help so far.

              Mitch

                If you have a bunch of HTML, try escaping out of PHP. Example:

                <?php
                if($foo == 'bar') {
                ?><p>This is some HTML!</p>
                <br/>
                <?php } else { ?>
                <p>Uh oh... $foo isn't bar... something's terribly wrong!</p>
                <?php
                }
                ?>

                  Thank You I think I have it now. I wasn't escaping out of the PHP block.

                    Write a Reply...