A Flash Developer Resource Site

Page 4 of 5 FirstFirst 12345 LastLast
Results 61 to 80 of 93

Thread: Load a movie into flash using a PHP file

  1. #61
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    As always, Keyone, very good .

    I'm gonna use it.

    Would you please explain sessions to me. And, would it still be secure if I did not use sessions?

    Thanks,
    Last edited by ninjakannon; 04-06-2006 at 01:52 PM.
    ninjakannon

    - My Website -

  2. #62
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    Sessions are a really simple feature (though can become more complex when customizing them).

    Anyway, in simple words, the session is a framework to make variables live through while the user browses your website. A session is mantained by cocckie (a little temporary text file).

    To learn sessions the first excercise would be to create two scripts, each one beginning with this line of code:
    PHP Code:
    session_start(); 
    in the first script add this code:
    PHP Code:
    $_SESSION['myVar'] = 'I am lucky!';
    echo 
    'I have set the variable, no go to the second file..'
    in the second script add this code:
    PHP Code:
    echo 'the variable is: ';
    echo 
    $_SESSION['myVar']; 
    Upload your files and type the address of the first one in your browser.
    When you read the text of the first file, type the address of the second file and look...

    even though the second file doesn't have any declaration of the variable, it knows what it is, and what it contains...

    Just simple and cool.


    Obviously there is much more to sessions than just that. But it's a way to show you what you can do with them.


    Anyway you don't need to use sessions in this particular case, you can have Flash send authorization user/pass at every request.
    Altruism does not exist. Sustainability must be made profitable.

  3. #63
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Sessions are absolutly the coolest thing since they put a pocket on a T-shirt. The new DW 8 makes using them simple work.

  4. #64
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    Thanks once again!

    I get it now, basicaly like a php version of flash's localConnection. I won't use it with this but it will prove useful.
    Sessions are absolutly the coolest thing since they put a pocket on a T-shirt
    Keep to date Geezer since the pocket on a T-shirt? Anyway I thought the phrase was since sliced bread...

    Cheers
    ninjakannon

    - My Website -

  5. #65
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    No, sliced bread is really OLD.

    And it's still hard to find a good T-shirt with a pocket on it.

  6. #66
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    Yeah, nice new phrase... I might addopt it :P.

    I think you've niticed a gap in the market for T-shirts with good pockets on. Maybe you should try and market them =P
    ninjakannon

    - My Website -

  7. #67
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    Hey what are you talking about... ? T-shirts? pockets?

    Where I come from, you don't wear t-shirts. You wear shirts. And light fabric is the coolest invention, so that we can wear suites even in the hot weather without falling dead in our sweat!

    Altruism does not exist. Sustainability must be made profitable.

  8. #68
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    This thread really has got a bit off subject now. I mean really, 'arguing' about what the coolest invention is!

    ...But then again...

    Aww who cares anyway, just keep typing (two more posts here and this will be the longest thread on the whole forum (I think))!

    ninjakannon

    - My Website -

  9. #69
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    You're right, we should talk about this in the coffee lounge.
    Anyway I've never used ANY Dreamweaver feature for backend programming. How does that work?

    I'm just used to handcode every bit of my work, which is bad, because makes me earn much, much less for my worktime...
    Altruism does not exist. Sustainability must be made profitable.

  10. #70
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    I also, have 'never used ANY Dreamweaver feature for backend programming', so you're gonna have to wait for Geezer for this one.

    I would be interested to know though.
    ninjakannon

    - My Website -

  11. #71
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    OK,

    I am just about to use $_SESSION.

    But how do I end a session? And how do I get rid of the session cookie? So that no data can be remembered.

    Cheers
    Last edited by ninjakannon; 04-07-2006 at 09:20 AM.
    ninjakannon

    - My Website -

  12. #72
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    PHP Code:
    <?php
    // Initialize the session.
    // If you are using session_name("something"), don't forget it now!
    session_start();

    // Unset all of the session variables.
    $_SESSION = array();

    // If it's desired to kill the session, also delete the session cookie.
    // Note: This will destroy the session, and not just the session data!
    if (isset($_COOKIE[session_name()])) {
       
    setcookie(session_name(), ''time()-42000'/');
    }

    // Finally, destroy the session.
    session_destroy();
    ?>
    For future quick reference, go to [url]http://www.php.net/[/php], it's easy and very complete... well obviously..being the official PHP resource!
    Altruism does not exist. Sustainability must be made profitable.

  13. #73
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    Right, thanks.
    Sorry, but I'm still not 100% on this:...
    PHP Code:
    <?php
    session_start
    ();
    session_name('mySessionName'); // Is this nesessary? If so, is it in the correct place?

    $_SESSION['myVar'] = 'this is my session variable';

    $_SESSION = array();

    // Would this delete the session cookie?
    if (isset($_COOKIE[session_name()])) { 
       
    setcookie(session_name(), ''time()-42000'/'); 
    }

    /* Or would this?:
    if (isset($_COOKIE[session_name('mySessionName')])) { 
       setcookie(session_name('mySessionName'), '', time()-42000, '/'); 
    }
    */

    session_destroy(); 
    ?>
    Regards,
    ninjakannon

    - My Website -

  14. #74
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    ok:

    1) You don't need to set a custom sessionName, unless you need to do so for specific needs.

    2) The session_name() function will set the session name to what you pass it (if you are passing it a string), and return the session name. So if you don't pass anything to the function, it will just return the session name:
    PHP Code:
    session_name('mySName');
    // the following lines of code do the same thing... but the first is dynamic...
    $curSessionName session_name();
    $curSessionName 'mySName'
    Hope this helps!

    In any case you rarely need to kill the session.
    What I do usually is to keep a variable in the session, that defines the ACCESS LEVEL of the user. When the user first accesses the site, it is at 0 (unidentified).
    Once the user logs in, it get's it's own account access level assigned to the session (1=simple user, 2=power user... N=webmaster).

    To logout, I just set the variable back to "0".. which will make the user be treated like an anonymous user again.

    Altruism does not exist. Sustainability must be made profitable.

  15. #75
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    So do I start the session, then set its name.

    And to do this bit of code:
    PHP Code:
    if (isset($_COOKIE[session_name('mySessionName')])) { 
       
    setcookie(session_name('mySessionName'), ''time()-42000'/'); 

    Would I specify the session name in session_name()?

    Thanks for this,
    ninjakannon

    - My Website -

  16. #76
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    I think you are getting confused.
    You start the session, you DO NOT set it's name (as there is no need to).

    That bit of code you repeated is to DESTROY the cookie (by setting it's expiration date to the past, forcing the browser to ignore or delete it). It is necessary only if you create the cookie in the first place.

    In fact to destroy a session you only need this:
    PHP Code:
    $_SESSION = array(); // this erases all the data in the session, by making a new clean array of it
    session_destroy(); // this kills the session instance in the server. 
    Altruism does not exist. Sustainability must be made profitable.

  17. #77
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Quote Originally Posted by keyone.it
    You're right, we should talk about this in the coffee lounge.
    Anyway I've never used ANY Dreamweaver feature for backend programming. How does that work?

    I'm just used to handcode every bit of my work, which is bad, because makes me earn much, much less for my worktime...
    Keyone, you owe it to yourself to upgrade to DW 8 if you don't already have it. I'll post some code below that Dreamweaver wrote for me on a php page, with just a few clicks, no typing, other than to fill in the popup form to set a few parameters, then to click OK. I know nothing about code. I'm an old man that got into computers about 6 years ago and have no schooling in it at all. So DW, for me, is the "tool of the ages". And not only that, but it all works.

    This code is the session variable that keeps you logged in and only allows logged in users with certain permissions set in the database to view any of a slew of pages in the admin section of this site.

    PHP Code:
    <?php
    if (!isset($_SESSION)) {
      
    session_start();
    }
    $MM_authorizedUsers "admin";
    $MM_donotCheckaccess "false";

    // *** Restrict Access To Page: Grant or deny access to this page
    function isAuthorized($strUsers$strGroups$UserName$UserGroup) { 
      
    // For security, start by assuming the visitor is NOT authorized. 
      
    $isValid False

      
    // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
      // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
      
    if (!empty($UserName)) { 
        
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
        // Parse the strings into arrays. 
        
    $arrUsers Explode(","$strUsers); 
        
    $arrGroups Explode(","$strGroups); 
        if (
    in_array($UserName$arrUsers)) { 
          
    $isValid true
        } 
        
    // Or, you may restrict access to only certain users based on their username. 
        
    if (in_array($UserGroup$arrGroups)) { 
          
    $isValid true
        } 
        if ((
    $strUsers == "") && false) { 
          
    $isValid true
        } 
      } 
      return 
    $isValid
    }

    $MM_restrictGoTo "/login/login.php";
    if (!((isset(
    $_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers$_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
      
    $MM_qsChar "?";
      
    $MM_referrer $_SERVER['PHP_SELF'];
      if (
    strpos($MM_restrictGoTo"?")) $MM_qsChar "&";
      if (isset(
    $QUERY_STRING) && strlen($QUERY_STRING) > 0
      
    $MM_referrer .= "?" $QUERY_STRING;
      
    $MM_restrictGoTo $MM_restrictGoTo$MM_qsChar "accesscheck=" urlencode($MM_referrer);
      
    header("Location: "$MM_restrictGoTo); 
      exit;
    }
    ?>

  18. #78
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    Well, Geezer just think about this. I find it difficult to find the will to learn how to use Dreamweaver's tools :P.

    Really!

    I am a self-tought programmer... I find it much easier to go about the web, search for info on my issues and handcode my scripts!

    I think I'll just have to stick to it...
    Altruism does not exist. Sustainability must be made profitable.

  19. #79
    Senior Member ninjakannon's Avatar
    Join Date
    Sep 2004
    Posts
    393
    You're just like me Keyone, I'm self taught too. I started learning php in the course of this thread, at the point where I said that yes I should be using a database.

    The one difference between you and me is that I believe that you are an adult, I am - on the other hand - only 15 years old.

    One question; do I have to state the name of a session (session_name('mySessionName')) to use it or do I just say: session_name()?
    ninjakannon

    - My Website -

  20. #80
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    To each his own. I would love to be able to hand code this stuff, but I figured I just didn't have 6 or 8 years left it would take to learn it. I want it and I want it now, without the learning curve.

    Instant gratification is so 21st century.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center