...

View Full Version : Skip Flash content with php session or cookies



RaimoD
01-02-2012, 04:24 PM
Hello!

I hope that I will find answer and you could be very helpfyll. So the question is:
I made flash based intro and placed it inside the index.php page, but I don`t want to play this flash content again and again for the person who are visiting my site second time. So I want to do some reforwarding to another page that holds all the content. But I don`t know how to do this. And which method could be better session or cookie.

Can samone explain to me this.

And thank you in advance!

mlseim
01-02-2012, 09:29 PM
I would use a cookie.

Post the PHP script you have for "index.php".

RaimoD
01-04-2012, 10:13 AM
Sorry, I don`t have any php code at all, but index page is simple plain code with flash embeding inside it.

mlseim
01-04-2012, 12:21 PM
So your opening page is called "index.php" ... is that correct.

What happens right now after the flash presentation is finished?
Does it go to another page?
And if so, what is the name of that other page (your main page)?

RaimoD
01-04-2012, 12:30 PM
yes, I wrote Actionscript, that forwards the client to the main page when presentation is done. It`s another directory with index page in it.

I know how to write Actionscript codes but do not know well php, probably i could do it in another way but my intropage in on directory web directory within index.php page, after intro is played, the script calls another direstory within main index page.

index.php goes to /main/index.php

BluePanther
01-04-2012, 02:30 PM
Use a cookie :).

At the top of your index.php page (above any doctype or <html> tags - the VERY top of the document), you could put something like this:


// Check for the cookie
if(isset($_COOKIE['visited'])){
// If it exists, set a boolean value
$visited = TRUE;
else{
// It doesn't exist - user has never been on this page before
$visited = FALSE;
// Set the cookie with an expiry time 30 days from now
setcookie('visited','true',time()+(60*60*24*30));
}

Then, surround your flash content in an if condition like


<?php
if(!$visited){
?>
<!-- FLASH CONTENT HERE -->
<?php
}
?>

That should work :)

RaimoD
01-04-2012, 02:36 PM
Thank you, then I probably do on else statement all other main page coding? On this hand I dont need this another directory at all

BluePanther
01-04-2012, 02:44 PM
Thank you, then I probably do on else statement all other main page coding? On this hand I dont need this another directory at all

You don't need an else for that if at all. It's just a check to display the flash content if $visited == false. If you wanted to stop the rest of the content being displayed at all, then you could add an else.

To clarify: Adding an else isn't needed; it will stop first time viewers from being able to view anything other than the flash. However, if that is your required functionality, go right ahead :)

RaimoD
01-04-2012, 02:48 PM
Okey, but could you show me exapmle, if the statement visited is true, how can i redirect the client to another page?

BluePanther
01-04-2012, 02:54 PM
Now that I know the entirety of your problem, I would change my solution.


if(isset($_COOKIE['visited'])){
// If it exists, redirect
header("location: somewhere.php");
else{
// It doesn't exist - user has never been on this page before
// Set the cookie with an expiry time 30 days from now
setcookie('visited','true',time()+(60*60*24*30));
// Put entire page contents in here
}

RaimoD
01-04-2012, 02:56 PM
Thank you, you save may day!

:)

I should learn php as well.

RaimoD
01-04-2012, 03:01 PM
And one more question
// Put entire page contents in here

so on this place I must start with all php and html elements as

print <html><header> and so on...?

BluePanther
01-04-2012, 03:17 PM
And one more question
// Put entire page contents in here

so on this place I must start with all php and html elements as

print <html><header> and so on...?

Yeah, it should be


if(isset($_COOKIE['visited'])){
// If it exists, redirect
header("location: somewhere.php");
else{
// It doesn't exist - user has never been on this page before
// Set the cookie with an expiry time 30 days from now
setcookie('visited','true',time()+(60*60*24*30));
// Put entire page contents in here
print '<html><head> etc. ';
}

Or, if it's easier,


if(isset($_COOKIE['visited'])){
// If it exists, redirect
header("location: somewhere.php");
else{
// It doesn't exist - user has never been on this page before
// Set the cookie with an expiry time 30 days from now
setcookie('visited','true',time()+(60*60*24*30));
// Put entire page contents in here
?>
<!-- Plain html in here. Additional PHP actions inside the html would be fine as well -->
<?php
}

RaimoD
01-04-2012, 03:57 PM
Thank you so much



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum