Advanced Search

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Session Variables

  1. #1
    Join Date
    Jul 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Session Variables

    Please Help me and teach me, I am a no-voice user.

    Presently my website is running on html javascript. I have flash player which uses the function popup and play i.e; when a user clicks Play button the flash player is opened in popup and plays the song and when user clicks on other song it gets added to the playlist, this works till the user is on same page, when he moves to other pages and tries to add song to the playlist a new popup page(which has player) is opened or the previous popup page is reloaded.

    I need session variables so that the other pages on my website know that the popup page is opened and only need add song to the playlist.

    I have a php template but it still not working with normal sessions.

    what kind of session variable are required, please if you have the code post it.

    Thank you

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    262
    Thanked 690 Times in 678 Posts

    Default

    I suggest just using a Javascript cookie. Or maybe trying to see if that window exists via Javascript.

    Sessions in PHP migt work, but how will you know when the window is opened? And closed? PHP won't automatically change a value when a page is closed, just when it's loaded.
    I know that flash can interact with PHP, so maybe you could use that?? But you can also use Flash+JS, so that's probably better.


    Using sessions in PHP is very easy.
    At the VERY START of EVERY page:
    PHP Code:
    <?php
    session_start
    ();
    .........
    That's all. That will make the session work.

    And again, this must be at the very start of your page and cannot be after any text output, including whitespace-- so this needs to be at the top of your file, before <html>, before Doctype, etc.


    Then within PHP you will use $_SESSION like any normal array in PHP.

    $_SESSION['myvariable'] = 'myvalue';


    echo $_SESSION['myvariable'];


    So you will need to do two things:

    1. On the popup page, set $_SESSION['popup'] = 1;, or something like that.
    2. On the main pages, use an if statement:
    PHP Code:
    if (!isset($_SESSION['popup'])) {
       echo 
    '<a href...... make popup.....</a>';

    But again, I think you would be better using Javascript for this, not PHP. I don't know how you would find out once the window has been closed using PHP. It's also hard using Javascript, but easier than PHP.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jul 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you for quick reply Djr33.
    I am testing on my local pc, i have installed apache server.

    Tell me if have done correct. (its not working)

    =========index.php and other pages have below code=========

    <?php
    session_start();
    if (!isset($_SESSION['popup'])) {
    echo '<a href="http://localhost/webiste/player.php"</a>';
    }
    ?>
    <head>
    -------==========
    =====
    ====..........

    </body>

    </html>


    AND

    =========player.php(this is a popup page)========
    <?php
    session_start();
    $_SESSION['popup'] = 1;
    ?>
    <html>

    ==
    ==

    ==
    </html>


    Thank you again

  4. #4
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    echo '<a href="http://localhost/webiste/player.php"</a>';
    Changed to
    echo '<a href="http://localhost/webiste/player.php">Player</a>';
    If you want a popup, you should really use javascript. But you could add target="_blank" to make a rudimentary pop up.
    P.S. You spelled website wrong
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    262
    Thanked 690 Times in 678 Posts

    Default

    Also, session_start() MUST go before EVERYTHING on the page:

    <?php
    session_start();
    if (!isset($_SESSION['popup'])) {
    echo '<a href="http://localhost/webiste/player.php"</a>';
    }
    ?>
    <!Doctype>
    <html>

    <head>
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Jul 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I did as you said but not working, any more suggesstion and any webiste where i can get the flash player with these features.

  7. #7
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Quote Originally Posted by djr33 View Post
    Also, session_start() MUST go before EVERYTHING on the page:

    <?php
    session_start();
    if (!isset($_SESSION['popup'])) {
    echo '<a href="http://localhost/webiste/player.php"</a>';
    }
    ?>
    <!Doctype>
    <html>

    <head>
    STOP:echo '<a href="http://localhost/webiste/player.php"</a>';
    REPLACE:echo '<a href="http://localhost/webiste/player.php">Player</a>';
    Really djr?
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    262
    Thanked 690 Times in 678 Posts

    Default

    Yes, because session_start() is a header function, it MUST be sent before any text data to the browser. The header is sent, then the text output. If you try to send more header info after, it won't work-- same with setting a cookie or doing a header redirect. Even \n before the <?php session_start();..... will cause this not to work.

    However, there is an obvious exception that you can have other PHP code as needed, as long as it doesn't output any text.

    For example:
    <?php
    $myvar = 1;
    session_start();


    You can also do something like:
    <?php
    if ($_COOKIE['username']) {
    session_start();
    }

    But whatever way you do this, it just must be the case that this happens before anything is output.

    So assuming a valid page with a doctype, session_start() must go before the doctype. And there can't be any extra spaces first.


    In general, though it doesn't always need to go right at the beginning of your PHP (though always before html), there's very rarely a reason not to put it first, and that always works, so it makes sense to me.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    I did as you said but not working
    Can you please post the code that you are using?
    any more suggestion and any website where i can get the flash player with these features.
    As for the flash music player:
    http://www.premiumbeat.com/flash_music_players/ <-plenty of free flash music players
    Last edited by fileserverdirect; 07-16-2010 at 03:33 PM. Reason: YAY! Senior Coder!
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  10. #10
    Join Date
    Jul 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Player Code - Wimpy

    =======main page code=====

    <script language="JavaScript" type="text/JavaScript">
    <!--

    // NOTE: These functions are used to open the pop up page

    var wimpyWindow;
    var winOpen=0;
    function wimpyPopPlayer(wimpyPopPage,theWidth,theHeight) {
    wimpyWindow = window.open(wimpyPopPage,'wimpyMP3player','width='+theWidth+',height='+theHeight);
    winOpen=1;
    }
    function wimpyPopPlayerWithFile(wimpyPopPage,initialFile,theWidth,theHeight) {
    wimpyWindow = window.open(wimpyPopPage+'?theFile='+initialFile,'wimpyMP3player','width='+theWidth+',height='+theHeight);
    winOpen=1;
    }
    function wimpyIsOpen(){
    if (winOpen==1){
    if (wimpyWindow.closed){
    return false;
    } else {
    return true;
    }
    } else {
    return false;
    }
    }
    function wimpyPopAndPlay(startOnLoad, theFile, theArtist, theTitle, graphicURL, hotlinkURL){
    if(wimpyIsOpen()){
    wimpyWindow.wimpy_addTrack(startOnLoad, theFile, theArtist, theTitle, graphicURL, hotlinkURL);
    } else {
    wimpyPopPlayerWithFile('player.php',theFile,'480','140');
    }
    }
    //-->

    </script>

    ===================
    These links are used to communicate and control the player in the popped up window.
    =========

    <a href="javascript:;" onClick="wimpyPopAndPlay(false, 'example4.mp3', 'My Artist', 'My Title', 'http://www.wimpyplayer.com', 'image.jpg')">
    - Add Track, but don't play
    </a>

    NO Js files on main page.

    =======player Code=======

    -->
    <script language='javascript' src='wimpy.js'></script>

    <!--
    This function is used to populate the player with a track when the pop up window is first launched.
    -->
    <script>
    function wimpyInitialize(defaultFile){

    var myWimpyConfigs = new Object();

    var qsParm = new Array();
    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i=0; i<parms.length; i++) {
    var pos = parms[i].indexOf('=');
    if (pos > 0) {
    var key = parms[i].substring(0,pos);
    var val = parms[i].substring(pos+1);
    qsParm[key] = val;
    }
    }


    // NOTE: The "playlist" configuration option is only used to manually list individual files. Similar to example 1 and 2), whereas "wimpyApp" is used to establish and external playlist file that Wimpy should OPEN.

    if(qsParm['theFile']){

    myWimpyConfigs.wimpyApp = "";
    myWimpyConfigs.playlist = qsParm['theFile'];
    } else {

    myWimpyConfigs.wimpyApp = defaultFile;
    myWimpyConfigs.playlist = "";
    }


    myWimpyConfigs.wimpySkin = "";
    myWimpyConfigs.startPlayingOnload = "yes";
    myWimpyConfigs.startOnTrack = "";
    myWimpyConfigs.autoAdvance = "";
    myWimpyConfigs.loopTrack = "";
    myWimpyConfigs.repeatPlaylist = "";
    myWimpyConfigs.randomPlayback = "";
    myWimpyConfigs.randomOnLoad = "";
    myWimpyConfigs.theVolume = "";
    myWimpyConfigs.infoDisplaySpeed = "";
    myWimpyConfigs.coverartBasename = "";
    myWimpyConfigs.popUpHelp = "";
    myWimpyConfigs.useSysCodePage = "";
    myWimpyConfigs.tptBkgd = "";
    myWimpyConfigs.bkgdColor = "#000000";
    myWimpyConfigs.wimpyWidth = "480";
    myWimpyConfigs.wimpyHeight = "140";
    myWimpyConfigs.startupLogo = "";
    myWimpyConfigs.defaultImage = "";


    makeWimpyPlayer(myWimpyConfigs);
    }
    </script>


    file attachment has wimpy.js - have look at it
    Last edited by wazaa; 07-16-2010 at 07:44 PM. Reason: missed the line

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
  •