koolaid Posted May 26, 2008 Share Posted May 26, 2008 Yes i am extremely new at this. Sorry i can not seem to wrap my head around sessions. It is supposed to be very straight forward i need to pass 1 variable from page to page via sessions. What am i doing wrong? start my session <?php session_start(); $_SESSION['username'] = $_POST['thename']; session_write_close(); ?> the next page <?php session_start(); echo $_SESSION['username']; ?> <br>username = <?php print $_SESSION['username'];?>.. Please and thank you!!!!! Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 26, 2008 Share Posted May 26, 2008 is there a form that submits $_POST['thename']? Quote Link to comment Share on other sites More sharing options...
koolaid Posted May 26, 2008 Author Share Posted May 26, 2008 yup, and it works fine on a mac in firefox, but not anywher else Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 26, 2008 Share Posted May 26, 2008 hm. i'd like to see more of the code. firefox will let you get away with stuff that might not work on other browsers. is your HTML FORM tag closed? is there anything before your PHP session_start()? Quote Link to comment Share on other sites More sharing options...
koolaid Posted May 26, 2008 Author Share Posted May 26, 2008 My form is in flash. I know flash is sending the var to the php file. I am collecting user data and writting it to my server via php. This is the entire php script that flash calls <?php session_start(); $_SESSION['username'] = $_POST['thename']; session_write_close(); ///my flash variables ///$_POST["repsName"] . $_POST["clientsName"]. $_POST["clientsPhone"]. $_POST["clientsUrl"]. $_POST["shortDescroption"]. $_POST["longDescription"]; $folder = "./files/".$_POST["thename"]."/"; if(!is_dir($folder)) mkdir($folder, 0755); $mode = file_exists($folder.'user_input.txt')?'a':'w'; // append if file exists otherwise create it $fp = fopen($folder.'user_input.txt',$mode); // open file foreach($_POST as $K=>$V) { if($K != '_searchKey') { fwrite($fp, "$K=$V\r\n"); // dump the contents of the $_POST array to the file } } fclose($fp); ?> Then flash executes this function when the data is sent (if you are not familiar with Action Script I can assure you that this part is functioning) [AS] myLv.onData = function():Void { status_txt.text = "save successful..."; getURL("http://www.molaeemedia.com/matt/testsDelete/session/varpassing.php","_self"); }; [/AS] Then when redirected via the flash it pulls up this page <?php session_start(); echo $_SESSION['username']; ?> <br>username = <?php print $_SESSION['username'];?>.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- saved from url=(0014)about:internet --> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>SWFObject embed by Geoff Stearns (basic) @ deconcept</title> <!-- SWFObject embed by Geoff Stearns geoff@deconcept.com http://blog.deconcept.com/swfobject/ --> <script type="text/javascript" src="swfobject.js"></script> <style type="text/css"> body { background-color: #eeeeee; font: .8em/1.3em verdana,arial,helvetica,sans-serif; } #info { width: 300px; overflow: auto; } #flashcontent { border: solid 1px #000; width: 300px; height: 300px; float: left; margin: 15px 20px; } </style> </head> <body> <div id="flashcontent"> <strong>You need to upgrade your Flash Player</strong> This is replaced by the Flash content. Place your alternate content here and users without the Flash plugin or with Javascript turned off will see this. Content here allows you to leave out <code>noscript</code> tags. Include a link to <a href="swfobject.html?detectflash=false">bypass the detection</a> if you wish. </div> <script type="text/javascript"> // <![CDATA[ var so = new SWFObject("check.swf", "check", "800", "500", "9", "#FF6600"); so.addVariable("username", "<?php echo $_SESSION['username'];?>"); // this line is optional, but this example uses the variable and displays this text inside the flash movie so.write("flashcontent"); // ]]> </script> </html> I really have been trying to do this on my own for three days now. I am at wits end if there ever was wits : ) Really, i only need to pass the one variable. It should be easy. Quote Link to comment Share on other sites More sharing options...
koolaid Posted May 26, 2008 Author Share Posted May 26, 2008 I forgot to add that it writes all the information i want it to write to my server. just not passing the var via session data. Do i need to assign a session id or something? Everything i read tells me that what i am doing should work. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 26, 2008 Share Posted May 26, 2008 oh, so you're essentially using flash as a browser to submit form data? that makes me wonder whether Flash can/will handle the session cookie properly. maybe not, which could be the problem. as you mentioned, you might need to retrieve the session_id and add it to the GetURL. Quote Link to comment Share on other sites More sharing options...
koolaid Posted May 26, 2008 Author Share Posted May 26, 2008 2 things: 1. if it was flash not retrieving the data it should still display in the <br>username = <?php print $_SESSION['username'];?>.. before the flash piece right? 2. how would i assign a session id and retrieve it? Quote Link to comment Share on other sites More sharing options...
koolaid Posted May 26, 2008 Author Share Posted May 26, 2008 OMG i got it!!!! I Knew it wasn't my flash because it was writting all the info i wanted to my server so that meant flash was sending the info. I was not assigning a value with my php to "username" prior to my form submitting data. So i was declring a variable then leaving it blank. So i just made it bob (working code below). For some reason that made all the difference. 2 days of pulling out my hair and naming my var bob was all I had to do. Well atleast no i can pass variables in between flash pieces via session data. Thanks a lot Bluesky for trying to help this dummy. //page 1: <?php session_start(); $_SESSION['username'] = 'bob'; echo $_SESSION['username']; session_write_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- saved from url=(0014)about:internet --> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>SWFObject embed by Geoff Stearns (basic) @ deconcept</title> <!-- SWFObject embed by Geoff Stearns geoff@deconcept.com http://blog.deconcept.com/swfobject/ --> <script type="text/javascript" src="swfobject.js"></script> <style type="text/css"> body { background-color: #eeeeee; font: .8em/1.3em verdana,arial,helvetica,sans-serif; } #info { width: 300px; overflow: auto; } #flashcontent { border: solid 1px #000; width: 300px; height: 300px; float: left; margin: 15px 20px; } </style> </head> <body> <div id="flashcontent"> <strong>You need to upgrade your Flash Player</strong> This is replaced by the Flash content. Place your alternate content here and users without the Flash plugin or with Javascript turned off will see this. Content here allows you to leave out <code>noscript</code> tags. Include a link to <a href="swfobject.html?detectflash=false">bypass the detection</a> if you wish. </div> <script type="text/javascript"> // <![CDATA[ var so = new SWFObject("start_session.swf", "start_session", "800", "500", "9", "#FF6600"); so.addVariable("username", "this is the user name for now"); // this line is optional, but this example uses the variable and displays this text inside the flash movie so.write("flashcontent"); // ]]> </script> </html> //the script that flash calls to write the info to the server and redefine username var <?php session_start(); $_SESSION['username'] = $_POST['thename']; session_write_close(); ///my flash variables ///$_POST["repsName"] . $_POST["clientsName"]. $_POST["clientsPhone"]. $_POST["clientsUrl"]. $_POST["shortDescroption"]. $_POST["longDescription"]; $folder = "./files/".$_POST["thename"]."/"; if(!is_dir($folder)) mkdir($folder, 0755); $mode = file_exists($folder.'user_input.txt')?'a':'w'; // append if file exists otherwise create it $fp = fopen($folder.'user_input.txt',$mode); // open file foreach($_POST as $K=>$V) { if($K != '_searchKey') { fwrite($fp, "$K=$V\r\n"); // dump the contents of the $_POST array to the file } } fclose($fp); ?> // finally the page flash redirects you to after your info has been written to the server and your var username has been written to session data //NOTE to flash users the code below uses swfobject.js to bypass the Active X Controles this code will not work with AC_RunActiveContent.js <?php session_start(); echo $_SESSION['username']; ?> <br>username = <?php print $_SESSION['username'];?>.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- saved from url=(0014)about:internet --> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>SWFObject embed by Geoff Stearns (basic) @ deconcept</title> <br>username = <?php print $_SESSION['username'];?>.. <!-- SWFObject embed by Geoff Stearns geoff@deconcept.com http://blog.deconcept.com/swfobject/ --> <script type="text/javascript" src="swfobject.js"></script> <style type="text/css"> body { background-color: #eeeeee; font: .8em/1.3em verdana,arial,helvetica,sans-serif; } #info { width: 300px; overflow: auto; } #flashcontent { border: solid 1px #000; width: 300px; height: 300px; float: left; margin: 15px 20px; } </style> </head> <body> <div id="flashcontent"> <strong>You need to upgrade your Flash Player</strong> This is replaced by the Flash content. Place your alternate content here and users without the Flash plugin or with Javascript turned off will see this. Content here allows you to leave out <code>noscript</code> tags. Include a link to <a href="swfobject.html?detectflash=false">bypass the detection</a> if you wish. </div> <script type="text/javascript"> // <![CDATA[ var so = new SWFObject("check.swf", "check", "800", "500", "9", "#FF6600"); so.addVariable("username", "<?php echo $_SESSION['username'];?>"); // this line is optional, but this example uses the variable and displays this text inside the flash movie so.write("flashcontent"); // ]]> </script> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.