koolaid Posted January 12, 2009 Share Posted January 12, 2009 ok i am stumped. I have a php page. This page calls 2 scripts w/o refreshing the page. <?php if (session_id()) { $_SESSION['theresumename'] = "yet to be defined"; }else{ session_start(); $time = time(); $date = $today = date("Ymd"); $id = $time + $date; session_id($id); print session_id(); $_SESSION['theresumename'] = "session just started"; echo $_SESSION['theresumename']; } ?> then when the user hits an upload button it successfully runs this script w/o refreshing that page if(!is_dir("./files")) mkdir("./files/", 0755); //move the uploaded file $replaceArr = array(" ", "#","!", "*", "^", "+"); $name = str_replace($replaceArr, "_", $_FILES['Filedata']['name']); $filename = "./files/".$name; srand(time()); $random = (rand()%9999); $ext = substr(strrchr($name, "."), 0); $name2 = str_replace($ext,'',$name); $arandomname = $name2.$random.$ext; $nizame = $arandomname; $_SESSION['theresumename'] = $nizame; EVERYTHING TO THIS POINT WORKS, then when the user hits submit it runs an email script. All the email script works accept for the one session variable. i don't understand. session_start(); if(isset($_SESSION['theresumename'])){ }else{ $_SESSION['theresumename'] = 'was not set'; } Thank you in advance. i have been trying to pass this one variable since 9 in the AM. I am at a loss. Quote Link to comment https://forums.phpfreaks.com/topic/140562-passing-session-data-between-scripts-wo-refresh-page/ Share on other sites More sharing options...
koolaid Posted January 12, 2009 Author Share Posted January 12, 2009 Sorry i forgot to add that i do have session_start(); on the second script Quote Link to comment https://forums.phpfreaks.com/topic/140562-passing-session-data-between-scripts-wo-refresh-page/#findComment-735568 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 Put session start at the top of the first script? Quote Link to comment https://forums.phpfreaks.com/topic/140562-passing-session-data-between-scripts-wo-refresh-page/#findComment-735569 Share on other sites More sharing options...
revraz Posted January 12, 2009 Share Posted January 12, 2009 You need to have session_start at the very top of your code on your first page. Quote Link to comment https://forums.phpfreaks.com/topic/140562-passing-session-data-between-scripts-wo-refresh-page/#findComment-735570 Share on other sites More sharing options...
koolaid Posted January 12, 2009 Author Share Posted January 12, 2009 Tnx guys good catch. Well, now i am at where i was this mprning. It is passing the session data but it changes from what it should be to a random number. Not sure why. This script will successfully writes the file to my server and will name it like this "filename0000.jpg" the zeros being a random #; but when i reference the var $_SESSION['theresumename'] in the next script it returns just a random 4 digit number, and not the same random 4 digit. <?php session_start(); error_reporting(E_ALL); //create the directory if(!is_dir("./files")) mkdir("./files/", 0755); //move the uploaded file $replaceArr = array(" ", "#","!", "*", "^", "+"); $name = str_replace($replaceArr, "_", $_FILES['Filedata']['name']); $filename = "./files/".$name; srand(time()); $random = (rand()%9999); $ext = substr(strrchr($name, "."), 0); $name2 = str_replace($ext,'',$name); $arandomname = $name2.$random.$ext; $nizame = $arandomname; $_SESSION['theresumename'] = $nizame; echo $_SESSION['theresumename']; if (file_exists($filename)) { move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$_SESSION['theresumename']); chmod("./files/".$_SESSION['theresumename'], 0777); }else { move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$name); chmod("./files/".$name, 0777); } if ( !($_SESSION['theresumename'] === $theresumename) ) $_SESSION['theresumename'] = $theresumename; echo $_SESSION['theresumename']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/140562-passing-session-data-between-scripts-wo-refresh-page/#findComment-735613 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 Where is $theresumename set? Quote Link to comment https://forums.phpfreaks.com/topic/140562-passing-session-data-between-scripts-wo-refresh-page/#findComment-735617 Share on other sites More sharing options...
koolaid Posted January 12, 2009 Author Share Posted January 12, 2009 The initial page: <?php session_start(); error_reporting(E_ALL); if (session_id()) { }else{ $time = time(); $date = $today = date("Ymd"); $id = $time + $date; session_id($id); print session_id(); echo "time = $time\r\n"; echo "date = $date\r\n"; $_SESSION['theresumename'] = "page opener"; echo $_SESSION['theresumename']; } ?> The first script i run The $_SESSION['theresumename'] is set under the comment //move the uploaded file [/code] <?php session_start(); error_reporting(E_ALL); //create the directory if(!is_dir("./files")) mkdir("./files/", 0755); //move the uploaded file $replaceArr = array(" ", "#","!", "*", "^", "+"); $name = str_replace($replaceArr, "_", $_FILES['Filedata']['name']); $filename = "./files/".$name; srand(time()); $random = (rand()%9999); $ext = substr(strrchr($name, "."), 0); $name2 = str_replace($ext,'',$name); $arandomname = $name2.$random.$ext; $nizame = $arandomname; $_SESSION['theresumename'] = $nizame; echo $_SESSION['theresumename']; if (file_exists($filename)) { move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$_SESSION['theresumename']); chmod("./files/".$_SESSION['theresumename'], 0777); }else { move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$name); chmod("./files/".$name, 0777); } if ( !($_SESSION['theresumename'] === $theresumename) ) $_SESSION['theresumename'] = $theresumename; echo $_SESSION['theresumename']; ?> [/code] The second script i run <?php session_start(); error_reporting(E_ALL); $sendTo = "mattpaxton@clearchannel.com"; $subject = "RESUME SUBMISSION (applicant)"; $headers = 'From:' . $_POST["email"] . "\r\n" . 'Reply-To:' . $_POST["email"] . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $headers .= "Content-type: text/html\r\n"; $path = $_POST["mypartialurl"]; $partial = $path ."files/"; $finalname = $_SESSION['theresumename']; $linktosend = $partial.$finalname; $message = 'RESUME SUBMISSION, name -'. $_POST["name"] . "\r\n \r\nTHE SUBMITTED INFO: \r\n \r\nAre you a creative thinker and problem solver? - " . $_POST["quest1"] . "\r\nDo others consider you a natural born leader? - " . $_POST["quest2"] . "\r\nAre you ready to set your own income potential? - " . $_POST["quest3"] . "\r\nAre you ready for responsibility from day one? - " . $_POST["quest4"] . "\r\nemail - " . $_POST["email"] . "\r\n\r\nAdditional comment / question - " . $_POST["message"] . "\r\n\r\nlink to uploaded resume:\r\n" . $linktosend; mail($sendTo, $subject, $message, $headers); ?> Quote Link to comment https://forums.phpfreaks.com/topic/140562-passing-session-data-between-scripts-wo-refresh-page/#findComment-735640 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 It isn't set on any of them pages Quote Link to comment https://forums.phpfreaks.com/topic/140562-passing-session-data-between-scripts-wo-refresh-page/#findComment-735650 Share on other sites More sharing options...
koolaid Posted January 12, 2009 Author Share Posted January 12, 2009 Thanks for your help man. It has to be Defined because my if statement (on page 2) writes the file to the server if (file_exists($filename)) { move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$_SESSION['theresumename']); chmod("./files/".$_SESSION['theresumename'], 0777); You know a lot more then I but this bit of code from page to is what names the file that the above code writes to the server it starts with the file that is selected from when the user browses and selects a file to upload: $_FILES['Filedata']['name'] The file name is posted from Flash. i know that part is working because it writes the file to my server with the proper file name. //move the uploaded file $replaceArr = array(" ", "#","!", "*", "^", "+"); $name = str_replace($replaceArr, "_", $_FILES['Filedata']['name']); $filename = "./files/".$name; srand(time()); $random = (rand()%9999); $ext = substr(strrchr($name, "."), 0); $name2 = str_replace($ext,'',$name); $arandomname = $name2.$random.$ext; $nizame = $arandomname; $_SESSION['theresumename'] = $nizame; echo $_SESSION['theresumename']; Quote Link to comment https://forums.phpfreaks.com/topic/140562-passing-session-data-between-scripts-wo-refresh-page/#findComment-735667 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 I don't mean the session isn't defined i mean the variable called $theresumename isn't defined. Look at the bottom of your 2nd script if ( !($_SESSION['theresumename'] === $theresumename) ) $_SESSION['theresumename'] = $theresumename; What is it comparing against :S Quote Link to comment https://forums.phpfreaks.com/topic/140562-passing-session-data-between-scripts-wo-refresh-page/#findComment-735670 Share on other sites More sharing options...
koolaid Posted January 12, 2009 Author Share Posted January 12, 2009 I see. That was a bit of code that i found on a forum from someone with a similar paroblem. I would think it should work is i removed that entirely right? Cause don't i define $_SESSION['theresumename'] with this code? $replaceArr = array(" ", "#","!", "*", "^", "+"); $name = str_replace($replaceArr, "_", $_FILES['Filedata']['name']); $filename = "./files/".$name; srand(time()); $random = (rand()%9999); $ext = substr(strrchr($name, "."), 0); $name2 = str_replace($ext,'',$name); $arandomname = $name2.$random.$ext; $nizame = $arandomname; $_SESSION['theresumename'] = $nizame; echo $_SESSION['theresumename']; or should i change the bit of code you are refering to, to this: if ( !($_SESSION['theresumename'] === $nizame) ) $_SESSION['theresumename'] = $nizame; echo $_SESSION['theresumename']; I am sorry i am so confused. I think i understand this less now then i did 10 hours ago. Quote Link to comment https://forums.phpfreaks.com/topic/140562-passing-session-data-between-scripts-wo-refresh-page/#findComment-735687 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 Sessions and variables are not the same This is where you define the session $_SESSION['theresumename'] = $nizame; But with this code if ( !($_SESSION['theresumename'] === $nizame) ) $_SESSION['theresumename'] = $nizame; You might be overwriting the session with something new, check all your variables are what you think Quote Link to comment https://forums.phpfreaks.com/topic/140562-passing-session-data-between-scripts-wo-refresh-page/#findComment-735690 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.