PHP w/cookies to load Flash video????

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smarsh
    New Member
    • Jul 2007
    • 18

    PHP w/cookies to load Flash video????

    Hi,

    I don't know PHP but it seems like the way to do this:

    I need a home page that loads a flash video into the HTML page and auto-plays for 1st time visitors. Repeat visitors (within 15 days) will have to click on the video to play it.

    I think a PHP script can be used to set or add to a cookie with a count and then check to see the count. If the count is 1 it calls for the auto-play video to be loaded. If the count is 2 or greater, it calls for the click to play video.

    I can make the 2 videos but I have no idea how to write the PHP.

    So, is this the way to do this or is there a better way?

    Can anyone help me put this script together?

    Thanks guys!
  • jx2
    New Member
    • Feb 2007
    • 228

    #2
    well
    its simple
    my idea is:
    [php]
    <?php
    //setup *************** *************** *******
    $videoHTML = "yourVideoPage. html";
    $withoutVideo = "yourNotVideoPa ge.html";
    $expire = 604800; //equvalent of 1 week
    // end of setup *************** *************** ***

    if( ! $visited){
    setcookie("visi ted",1,time()+$ expire);
    include($videoH TML);
    }else {
    include($withou tVideoHTML);
    }
    [/php]

    save it as yourfilename.ph p

    well that is it :-)

    i didnt test it but it should work fine if you have any question post again

    regards
    jx2

    Comment

    • kovik
      Recognized Expert Top Contributor
      • Jun 2007
      • 1044

      #3
      Originally posted by jx2
      [php]if( ! $visited)[/php]
      This line implies that you are using register_global s. Bad jx2, bad! The correct way to do this is:

      [php]if (!$_COOKIE['visited'])[/php]

      Comment

      • smarsh
        New Member
        • Jul 2007
        • 18

        #4
        Thanks for the script work guys!

        One thing though: the video is planned to go on the index.html page. I was hoping to keep visitors there by checking the cookie via PHP, then loading one or the other flash video into the index.html page. Is that possible? Is it too slow? If not, does the index page become a simple redirect to one or the other video pages? If it redirects, I'm concerned with search engines thinking something illegal is going on...

        Thanks again!

        Comment

        • jx2
          New Member
          • Feb 2007
          • 228

          #5
          Originally posted by volectricity
          This line implies that you are using register_global s. Bad jx2, bad! The correct way to do this is:

          [php]if (!$_COOKIE['visited'])[/php]
          LOL i know I know bad bad lazy me :-)

          lol

          regards
          jx2

          Comment

          • jx2
            New Member
            • Feb 2007
            • 228

            #6
            Originally posted by smarsh
            Thanks for the script work guys!

            One thing though: the video is planned to go on the index.html page. I was hoping to keep visitors there by checking the cookie via PHP, then loading one or the other flash video into the index.html page. Is that possible? Is it too slow? If not, does the index page become a simple redirect to one or the other video pages? If it redirects, I'm concerned with search engines thinking something illegal is going on...

            Thanks again!
            well if you save the script i wrote for you into index.php
            you will not have to do anything more it will work fine
            it will not redirect !!! it "change" the contents of index.php
            so the adress of your page will be always the same e.g.
            www.yourdomain. com/index.php regardless if its displays video or not

            regards
            jx2

            Comment

            • smarsh
              New Member
              • Jul 2007
              • 18

              #7
              OK. I think I learned something - let me run this by you...

              No index.html instead index.php. index.php is just the script with no HTML anything. The script calls one or the other html web page named in the script. In my case the pages are equivalent except for the video I put in each. All links on the site to "home" are linked to index.php

              In this way the script sets a new cookie or reads an existing cookie and then calls the content to take the place of the script. After the browser is done loading, someone viewing the "home page" source would only see the content from the called html page and never the script.

              Do I get it?

              Also, if I want the "videoHTML" page to be allowed say 3 times (instead of 1) before switching to "withoutVid eo" what would I have to change in the script?


              For my education: PHP can be written for other applications to be embedded in HTML like javascript right?
              Last edited by smarsh; Aug 14 '07, 05:47 PM. Reason: forgot something

              Comment

              • jx2
                New Member
                • Feb 2007
                • 228

                #8
                Originally posted by smarsh
                OK. I think I learned something - let me run this by you...

                No index.html instead index.php. index.php is just the script with no HTML anything. The script calls one or the other html web page named in the script. In my case the pages are equivalent except for the video I put in each. All links on the site to "home" are linked to index.php

                In this way the script sets a new cookie or reads an existing cookie and then calls the content to take the place of the script. After the browser is done loading, someone viewing the "home page" source would only see the content from the called html page and never the script.

                Do I get it?

                Also, if I want the "videoHTML" page to be allowed say 3 times (instead of 1) before switching to "withoutVid eo" what would I have to change in the script?


                For my education: PHP can be written for other applications to be embedded in HTML like javascript right?
                yeah you ve got it :-)
                php can be enbedded into html or html can by enbeddet into php :-) i know sounds strange

                index.php e.g. [html]
                <html>
                <body>
                <?php
                if( ! $visited) echo"play video - your html";
                else echo "dont play video- your html";
                ?>
                </body>
                </html>
                [/html]or in php
                [php]
                <?php
                echo "<html><bod y>";

                if( ! $visited) echo"play video - your html";
                else echo "dont play video- your html";

                echo "</body></html>";

                ?>[/php]

                all depends what is more comfortable for you

                regards
                jx2

                Comment

                • smarsh
                  New Member
                  • Jul 2007
                  • 18

                  #9
                  Thanks very very much jx2!!!

                  I learned a lot from this little exercise...

                  I'm sticking with the no html .php approach for this one. When I learn more about PHP I'll try some simple embedded scripts.

                  The last issue with this script is still:

                  If I want the "videoHTML" page to be allowed say 3 times (instead of 1) before switching to "withoutVid eo" what would I have to change in the script?

                  Comment

                  • jx2
                    New Member
                    • Feb 2007
                    • 228

                    #10
                    Originally posted by smarsh
                    [I][B]
                    If I want the "videoHTML" page to be allowed say 3 times (instead of 1) before switching to "withoutVid eo" what would I have to change in the script?
                    lol :-) you really want me to write it for you:-)
                    okey
                    lok at that: [php]
                    <?php
                    //setup *************** *************** *******
                    $videoHTML = "yourVideoPage. html";
                    $withoutVideo = "yourNotVideoPa ge.html";
                    $expire = 604800; //equvalent of 1 week
                    // end of setup *************** *************** ***
                    setcookie("visi ted", $visited++ ,time()+$expire );
                    if( $visited<3 ){
                    include($videoH TML);
                    }else {
                    include($withou tVideoHTML);
                    }[/php]

                    it should work

                    regards
                    jx2

                    Comment

                    • smarsh
                      New Member
                      • Jul 2007
                      • 18

                      #11
                      Originally posted by jx2
                      lol :-) you really want me to write it for you:-)
                      I know... I'm still a novice - in over his head... but I'm trying. I just don't know enough yet...

                      No matter what I do I can't get the revised version to go past the videoHTML page. I visited way over 3 times but it won't go. Is there a syntax issue or something I just don't see?

                      Thanks.

                      Comment

                      • jx2
                        New Member
                        • Feb 2007
                        • 228

                        #12
                        [php]<?php
                        //setup *************** *************** *******

                        $page1 = '<html>page1 ----------- insert your html here---------</html>';

                        $page2 = '<html>page2 ----------- insert your html here---------</html>';

                        $expire = 604800; //equvalent of 1 week
                        $howMany = 3;

                        //$visited = 0; // uncomment it if you want to reset counter

                        // end of setup *************** *************** ***


                        $visited++ ;

                        setcookie("visi ted", $visited ,time()+$expire );
                        if( $visited <= $howMany ){
                        echo $page1;
                        }else {
                        echo $page2;
                        }[/php]

                        make it simplier is imposible :-)

                        i hope that helps

                        regards
                        jx2

                        Comment

                        • smarsh
                          New Member
                          • Jul 2007
                          • 18

                          #13
                          THANKS jx2!!!

                          That really helps. And... I really learned something. I made a couple of changes to that last script so that it calls the pages instead of the inserted html. I know that's not much expertise, but it's more than I could do a few days back!

                          I look forward to learning PHP and maybe one day I can give some help to someone here.

                          Comment

                          Working...