www.webdeveloper.com
Results 1 to 3 of 3

Thread: script creates cookie onclick

  1. #1
    Join Date
    Feb 2011
    Posts
    2

    script creates cookie onclick

    Hi, I'm doing blog in html/php/mysql but i need one script that does the job that those 3 can't.

    I need script that makes cookie when i click on link and then gets me to this URL: http://tuupurid.zzl.org/library/blog/muudatest.php
    Cookie name shoud be "BLOG_ID"
    Cookie value should be php variable $ID(value is gotten from mysql tabel).
    Cookie should expire after 30mins.
    Cookie should work in entire domain.

    I hope that someone could help me

  2. #2
    Join Date
    Feb 2011
    Posts
    25
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Test Page</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <p>
    I need script that makes cookie when i click on link and then gets me to this URL: http://tuupurid.zzl.org/library/blog/muudatest.php
    Cookie name shoud be "BLOG_ID"
    Cookie value should be php variable $ID(value is gotten from mysql table).
    Cookie should expire after 30mins.
    Cookie should work in entire domain. 
    
    <p>
    <?php $ID = "someUser"; ?>
    
    <a href='http://tuupurid.zzl.org/library/blog/muudatest.php' onclick='setCookie( "BLOG_ID", "<?php echo $ID;?>", "secs=1800", "/" )'>GO THERE</a>
    
    <script type='text/javascript'>
    
    function setCookie( cName, cValue, days, cPath, cDomain, cSecure )
    {
     var dt = new Date(), 
         expSecs = ( expSecs = days.toString().match( /\bsecs\s*=\s*(\d+)/i ) ) ? Number( expSecs[ 1 ] ) : 0,
         params = ( days ? ( ";expires=" + new Date( expSecs ? ( dt.setTime( dt.getTime() + expSecs * 1000 ) )                                                          : ( dt.setDate( dt.getDate() + days) ) ).toUTCString() ) : "" )
                + ( cPath ? (";path=" + cPath) : "" )
                + ( cDomain ? ";domain=" + cDomain : "" )
                + ( cSecure ? ";secure" : "" );
    
     document.cookie = cName + "=" + encodeURIComponent( cValue ) + params;
    }
    
    </script>
    </body>
    </html>

  3. #3
    Join Date
    Feb 2011
    Posts
    2
    Thanks for answering so fast. That did the trick

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles