Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: If cookie is set, then display content of a different div

  1. #11
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    No problem, I'm glad to help.

    Here on DD, we like to keep things organized. In an effort to do so, you have the option to set a thread to resolved when an issue is fixed. To make the status of the thread resolved:
    1. Go to your first post
    2. Edit your first post
    3. Click "Go Advanced"
    4. In the dropdown next to the title, select "RESOLVED"
    Jeremy | jfein.net

  2. The Following User Says Thank You to Nile For This Useful Post:

    KennyP (11-07-2010)

  3. #12
    Join Date
    Dec 2009
    Location
    NY NY USA
    Posts
    230
    Thanks
    158
    Thanked 1 Time in 1 Post

    Default

    Sorry Nile, I had composed a long reply, but when I clicked submit, I had been logged out. When I logged in again the message was lost.

    I'll now recostruct it and will post again soon.
    Last edited by KennyP; 11-06-2010 at 01:00 AM.

  4. #13
    Join Date
    Dec 2009
    Location
    NY NY USA
    Posts
    230
    Thanks
    158
    Thanked 1 Time in 1 Post

    Default

    Here's the short version...

    If I remove all links (not written in PHP) from the text in the second visit div, and I also remove all the div style formatting, it works. Likewise in the first visit div, wherein I need to display a ticker; the non-PHP code generates parsing errors as shown below for the lines of the ticker code...

    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'
    Code:
    } else {
    echo "<div style="text-align:justify;" class="style59"> First visit text"; 
    echo "<a href='my_page.php'>First visit linked text!</a>
    <br>
    <span class="style59" id="anID"     
       onmouseover="AT_Pause()" 
       onmouseout="AT_Resume()"></span>
    <span><em><script type="text/javascript" src="AttentionTicker/AttentionTickerInclude.php?anID">
    </script></em></span>
    </div>";
    }
    ?>
    Therefore, your code works perfectly, and I managed to get the first visit link to work, but I hit a bump.

    If you would you please translate the rest of the non-PHP code to PHP, then the entire action I'm trying to perform would work.

    Thanks again Nile
    Last edited by jscheuer1; 11-06-2010 at 03:52 PM. Reason: formatting

  5. #14
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Don't echo the html if there's multiple lines, it's easier to just close the php then re-open it when finished.

    PHP Code:
    } else {
    ?>
    <div style="text-align:justify;" class="style59"> First visit text";
    <a href='my_page.php'>First visit linked text!</a>
    <br>
    <span class="style59" id="anID" onmouseover="AT_Pause()" onmouseout="AT_Resume()"></span>
    <span><em><script type="text/javascript" src="AttentionTicker/AttentionTickerInclude.php?anID"></script></em></span>
    </div>
    <?php
    }
    Corrections to my coding/thoughts welcome.

  6. The Following User Says Thank You to bluewalrus For This Useful Post:

    KennyP (11-07-2010)

  7. #15
    Join Date
    Dec 2009
    Location
    NY NY USA
    Posts
    230
    Thanks
    158
    Thanked 1 Time in 1 Post

    Default

    Thank you bluewalrus. I used Nile's code just as you recommended and it's working perfectly.

    Thanks again BeverleyH, Nile and bluewalrus for all the replies.

    Kenny

  8. #16
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    No problem! Sorry for not responding before. This happens me to where it tells you you need to log in, and when you go to log in your message is gone. When you get this error message it's better to copy everything in the text box, and then log in again, and then paste.
    Jeremy | jfein.net

  9. The Following User Says Thank You to Nile For This Useful Post:

    KennyP (11-07-2010)

  10. #17
    Join Date
    Dec 2009
    Location
    NY NY USA
    Posts
    230
    Thanks
    158
    Thanked 1 Time in 1 Post

    Default

    Hello again guys:

    Thanks again for your help. Your script of course works perfectly. However, I had to re-open the topic as I hit the following snag, and I just can't solve it. Therefore I beg your help again.

    The index page on the site I'm working on checks for a cookie. If not found, it redirects to a welcome page, and in turn, the welcome page redirects back to the index page.
    By now, the cookie for the two divs has already been set, counting as the first visit. Therefore, the first time div never gets displayed.

    As I see it, in order for this to work, the redirect to welcome page cookie code would need to precede the two divs cookie code, as follows:

    Code:
    <script type="text/javascript" src="scripts/cookie.js"></script>
    <?
    	//test for existence of cookies... if the cookie from welcome page has not been set...
    	if(!$_COOKIE[userlogin]){
    ?>
    	<script type="text/javascript">
    	// name, value, expires, path, domain, secure
    	Set_Cookie( 'test', 'none', '', '/', '', '' );
    	
    	// if Get_Cookie succeeds, cookies are enabled, since the cookie was successfully created.
    	if ( Get_Cookie( 'test' ) )
    	{
    		cookie_set = true;
    		// name, path, domain
    		// make sure you use the same parameters in Set and Delete Cookie.
    		Delete_Cookie('test', '/', '');
    		window.location = 'welcome-index.php';
    	}
    	// if the Get_Cookie test fails, cookies are not enabled for this session.
    	else
    		cookie_set = false;
    	</script>
    <? 	
    	} 
    ?>
    
    
    
    <?php
    $revisit = false;
    if(isset($_COOKIE['div'])){
      $revisit = true;
    } else {
      setcookie('div', true, 5184000 + time()); //hold fo 2 months
      $revisit = false;
    }
    ?>
    <!-- END cookies  -->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    ...however, in the above order the index page generates... "Warning: Cannot modify header information...(output started...index.php) in .....index.php on line..."

    Is there a way to write the two codes so that they can be left in the above order?

    Alternatively, if the order of the two codes is reversed, can the divs cookie code be altered to display the first time div on the second visit, and then to display the second time div as of the third visit onward?


    If it helps, this is the site I'm currently working on...

    billyjoeconor.com


    Thanks,

    Kenny
    Last edited by KennyP; 11-07-2010 at 09:34 AM.

  11. #18
    Join Date
    Dec 2009
    Location
    NY NY USA
    Posts
    230
    Thanks
    158
    Thanked 1 Time in 1 Post

    Default Got it to work!

    Hey guys,

    I actually got it to work. I used a PHP script for the re-direct to the welcome page. When I entered them as two separate scripts (one following the other) it did not work. But when I removed the closing tag of the first script, and the opening tag of the second script (leaving them as one script as you see below), it works. I'll leave it as it is unless you see something wrong with it.

    Thanks again guys. I couldn't have done it without your help...but I guess you already knew that!

    On the home page:

    Code:
    <?php
    if(!isset($_COOKIE['no_splash'])) { 
    // If no cookie, take them to the splash page.
    header ('Location: welcome.php');
    exit;
    } else 
    { 
    }
    // Determine which div should display.
    $revisit = false;
    if(isset($_COOKIE['div'])){
      $revisit = true;
    } else {
      setcookie('div', true, 7200 + time()); //hold for 2 hrs
      $revisit = false;
    }
    ?>
    On the splash page:

    Code:
    <?
    setcookie('no_splash', 'anonymous', time()+7200);
    ?>
    Last edited by KennyP; 11-07-2010 at 05:30 PM.

  12. #19
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Glad to help?
    Jeremy | jfein.net

  13. The Following User Says Thank You to Nile For This Useful Post:

    KennyP (11-07-2010)

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
  •