View Full Version : Session Variables
wazaa
07-14-2010, 04:20 PM
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
djr33
07-14-2010, 04:35 PM
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
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:
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.
wazaa
07-14-2010, 06:56 PM
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
fileserverdirect
07-15-2010, 03:11 AM
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 :p
djr33
07-15-2010, 07:47 AM
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>
wazaa
07-15-2010, 01:59 PM
I did as you said but not working, any more suggesstion and any webiste where i can get the flash player with these features.
fileserverdirect
07-15-2010, 04:44 PM
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?
djr33
07-15-2010, 05:43 PM
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.
fileserverdirect
07-16-2010, 03:31 PM
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
wazaa
07-16-2010, 07:42 PM
=======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
fileserverdirect
07-17-2010, 02:00 AM
Erm, I kind of meant the php code, the js is not really necessary to solve the problem, If you have a problem the the javascript, please post it in the javascript section (and remeber to use [CODE] tags!)
--
The problem with new windows and sessions is that different web browsers treat windows differently, when a new tab is open in browser X no new session is generated, however when a new window is opened in browser X, a new session is generated. In browser Y, all new windows open in tabs, thus keeping the session, however when a new window is opened via JS (what your doing) it immediately blocks it and requires a refresh of the page thus tampering with what the script belives as an open window. This varies on a browser to browser basis. (IE Quirk, no sessions are stored if there is a query string with abnormal characters like underscores)
--
Now Cookies would not require php, and it could be managed 100% though javascript, but if the window is ever closed, it would mess up the entire flow.
--
To get the php session to work, despite my rant about it, copy all the code in the previous posts (with the fixed <a> tags!) to the opening page, then in the popup page:
<?
session_start();
$_SESSION['popup']=true;
?>
dub dub dub js player stuff
Once the opening page is reloaded, you should be able to use an if statement on that to decide what content to show.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.