PDA

View Full Version : First Visit on phpBB forum shows this.html, check a box and....



k12onos
11-01-2006, 01:44 AM
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.

tech_support
11-01-2006, 04:36 AM
You'll have to use cookies for that and it should be in the PHP section.

k12onos
11-01-2006, 07:49 AM
oh i see, thanks tech_support for making it clear.
anyway did anyone know how to do that ?

and again thanks before guys ;)

codeexploiter
11-01-2006, 07:55 AM
Steps to set a cookie using PHP can be found here (http://php.about.com/od/advancedphp/qt/php_cookie.htm)

Steps to set a cookie using client side javascript can be found here (http://techpatterns.com/downloads/javascript_cookies.php)

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.

k12onos
11-01-2006, 08:16 AM
ok i got this code here :


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 ?

codeexploiter
11-01-2006, 08:37 AM
<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

<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.

tech_support
11-01-2006, 08:40 AM
Second part


<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()

k12onos
11-01-2006, 08:47 AM
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



// 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 !

codeexploiter
11-01-2006, 08:55 AM
Use document.forms['f1'].submit() not document.f1.submit()


tech_support, can you tell me why not to use document.f1.submit(); ?

k12onos
11-01-2006, 09:01 AM
oh, codeexploiter, i think what you ment in the cookie.php file is this right ?


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 :)

codeexploiter
11-01-2006, 09:07 AM
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" : "" );
}


You've mentioned the clien side cookie setting code. If you are going for a client side cookie setting code then there is no need for a php script.

In my first posting i've specified a link where it explained that how you can create a cookie using PHP.

Can you tell me using which method you need to create the cookie client side or server side?

k12onos
11-01-2006, 09:18 AM
i want to create a client side cookie :) im very sorry that i didnt mention it before,
so what i must do to put the code to excecute only when the person check the chekbox ?

will this code you gave work for clien side cookie ?

<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>

codeexploiter
11-01-2006, 09:29 AM
If you are looking for a client side cookie then remove the javascript code i've provided.

From the FORM tag remove action and method attributes

In the onClick event of your check box call the javascript function you have to create a cookie (remove the frmSubmit())

Call the Set_Cookie() with all the necessary parameters

k12onos
11-01-2006, 10:15 AM
thank you very much codeexploiter :)

now the Get Cookie part



// 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 ) );
}




how to make it redirect to another page when the cookie i mention exist ?
is it with this code
if ( Get_Cookie( 'your_cookie' ) )
?
then how to make it to redirect ?



and thank a lot again for your guidance !!

codeexploiter
11-01-2006, 10:25 AM
if(Get_Cookie('your_cookie'))
document.location.href = "thepagethevisitorwantstogo.html";

for ex:
document.location.href="http://www.google.com will redirect you to google

k12onos
11-01-2006, 10:41 AM
oh i see,

now i need some help to set the cookie parameters



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" : "" );
}


can you give me the example to fill that code ?
i mean the parameter like path, cookie name and the others, im new to java script so i dont know how to fill in those lines.

thank you very much :)

codeexploiter
11-01-2006, 11:07 AM
Set_Cookie( 'conf', 'redirect', 30, '/', '', '' );

The first parameter is the name of the cookie, the second one is the value of the cookie, the next one means that from the date onwards the cookie will be valid for 30 days and the cookie is set to your root folder.

Don't forget to put in empty quotes for the unused parameters.

k12onos
11-01-2006, 11:10 AM
what about the values below that ?

so we didnt need to change


{
// 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" : "" );
}

??


phew i thought i need to fill that out, thank you very very much codeexploiter !!

codeexploiter
11-01-2006, 11:44 AM
nope at the moment

tech_support
11-01-2006, 09:38 PM
tech_support, can you tell me why not to use document.f1.submit(); ?
Twey said so.

codeexploiter
11-02-2006, 03:26 AM
Twey said so.

You could've mentioned the thread where Twey said that. So that people can learn new things that they don't know.