Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: First Visit on phpBB forum shows this.html, check a box and....

  1. #1
    Join Date
    Aug 2006
    Posts
    58
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default First Visit on phpBB forum shows this.html, check a box and....

    i searched www.dynamicdrive.com but i found nothing about this kind of situation.

    let me place this right, i have a phpbb forum in www.this.com (the forum is located on the root dir which is www.this.com instead of www.this.com/forum).

    what i want is,
    when a person surf and the first time come to my forum, it will show a portal page which is in www.this.com/this.html, And there is a box which says
    []check this box to never see this portal again.
    when a person check that box, and when he came to my forum again, he will not see the portal and directly go to www.this.com/index.php (which is the forum index)

    can you telll me how to do it like that ?

    thank you very much before.

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    You'll have to use cookies for that and it should be in the PHP section.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Aug 2006
    Posts
    58
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default

    oh i see, thanks tech_support for making it clear.
    anyway did anyone know how to do that ?

    and again thanks before guys

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Steps to set a cookie using PHP can be found here

    Steps to set a cookie using client side javascript can be found here

    It doesn't mean that once you set the cookie it always work as it supposed. It will work untile the cookie is present in the client machine. If the client remove the cookie then the supposed operation won't work.

    Methods based on Cookies are not foolproof.

  5. #5
    Join Date
    Aug 2006
    Posts
    58
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default

    ok i got this code here :

    Code:
    function Set_Cookie( name, value, expires, path, domain, secure ) 
    {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );
    
    /*
    if the expires variable is set, make the correct 
    expires time, the current script below will set 
    it for x number of days, to make it for hours, 
    delete * 24, for minutes, delete * 60 * 24
    */
    if ( expires )
    {
    expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );
    
    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
    ( ( path ) ? ";path=" + path : "" ) + 
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
    }

    now is it possible to put it in a check box, i mean when a person click the checkbox the script will run,
    the check box is something like this right:
    <input type="checkbox" name="C1" value="ON">
    then how to put the script IN it ?

  6. #6
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    HTML Code:
    <form name="f1" method="POST" action="cookie.php">
    <input type="checkbox" name="chk" onClick="frmSubmit();">click me if you don't want to veiw this file
    </form>
    The above is the first part, the above code is the skelton you'll have in your page where you have the checkbox that you mentioned in your page. If you look at the FORM tag the name is f1 the http method going to use is POST and the server-side file which is going to be invoked is named cookie.php. cookie.php is the file in which you have the PHP script for setting a cookie in your user's machine.

    Second part
    Code:
    <script type="text/javascript" >
    function frmSubmit() 
    {
    	document.f1.submit();
    }
    </script>
    Place the above javascript code anywhere in the page <HEAD> section will do.

    Now whenever you click the checkbox it will invoke frmSubmit() that will submit the form to the cookie.php file. Now you have to write code for retrieving the cookie and based on the value you need to develop code to redirect the user who have checked the checkbox into another page.

  7. #7
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Quote Originally Posted by codeexploiter
    Second part
    Code:
    <script type="text/javascript" >
    function frmSubmit() {
    document.f1.submit();
    }
    </script>
    Place the above javascript code anywhere in the page <HEAD> section will do.
    Use document.forms['f1'].submit() not document.f1.submit()
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  8. #8
    Join Date
    Aug 2006
    Posts
    58
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default

    thanks for the explanation tech_support,

    now what should i fill in this cookie.php file ? or simply what php code is the cookie.php file must contain ?
    im a little confused in this part.
    im just a newbie here :P


    and then

    Code:
    // this function gets the cookie, if it exists
    function Get_Cookie( name ) {
    	
    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ( ( !start ) &&
    ( name != document.cookie.substring( 0, name.length ) ) )
    {
    return null;
    }
    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ";", len );
    if ( end == -1 ) end = document.cookie.length;
    return unescape( document.cookie.substring( len, end ) );
    }
    this is the Get Cookie part, where should i put

    if ( Get_Cookie( 'your_cookie' ) ) ??
    and if i want to redirect do i have to put
    if ( Get_Cookie( 'your_cookie' ) ) redirect to http://something , or what ?


    thank you a lot codeexploiter and tech_support !

  9. #9
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Quote Originally Posted by tech_support
    Use document.forms['f1'].submit() not document.f1.submit()
    tech_support, can you tell me why not to use document.f1.submit(); ?
    Last edited by codeexploiter; 11-01-2006 at 09:07 AM.

  10. #10
    Join Date
    Aug 2006
    Posts
    58
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default

    oh, codeexploiter, i think what you ment in the cookie.php file is this right ?

    Code:
    function Set_Cookie( name, value, expires, path, domain, secure ) 
    {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );
    
    /*
    if the expires variable is set, make the correct 
    expires time, the current script below will set 
    it for x number of days, to make it for hours, 
    delete * 24, for minutes, delete * 60 * 24
    */
    if ( expires )
    {
    expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );
    
    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
    ( ( path ) ? ";path=" + path : "" ) + 
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
    }
    so that code must be in cookie.php file ?

    and can you answer my post above you, still got something to figure out :P

    thanks before

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
  •