UbH Posted January 9, 2008 Share Posted January 9, 2008 Let me dive right in. [sTEP ONE] I have a form with about 20+ items for a user to fill out. Upon hitting submit my PHP script gets called. "nominationSubmit.php" [sTEP TWO] With this script I create a directory on the web server based on the "first" and "last" name fields the user filled out on the previous forms page. [sTEP THREE]<PROBLEM BEGINS Then I redirect them to another PHP/HTML forms page via meta tag that allows them to upload up to 5 files to this newly created directory on the web server, again by referencing variables from our first forms page. [sTEP FOUR]<PROBLEM CONTINUES After they have browsed for their files to upload and hit submit I take them to a third PHP script that uploads and moves the files to their proper locations & build an email message with URLs of the new uploaded files to be send to me in this email as well. Again all by referencing variables from our first forms page. All the scripts are working when going straight from the first forms page over to a single php script (removing the uploading process of course) But dividing all the scripts into these 4 steps I get no variable passing beyond the second step. How do I pass the variables that get assigned from the first forms page over to my last steps?? Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/ Share on other sites More sharing options...
Norsk.Firefox Posted January 9, 2008 Share Posted January 9, 2008 Use sessions and save $_POST as session. session_start(); in top of the three last pages in the two last pages you change $_POST with $_SESSION and as the last thing in the second file you put <?php foreach($_POST as $n => $v) $_SESSION[$n] = $v; ?> This just tell you a simple way to do it, you should try include some type of security. Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-434933 Share on other sites More sharing options...
kratsg Posted January 9, 2008 Share Posted January 9, 2008 This just tell you a simple way to do it, you should try include some type of security. In order to ensure security, just make sure that you've validated all fields before saving them into sessions, and each time you call the session variable, make sure the value fits and it hasn't been manipulated (IE: use mysql_real_escape_string(), stripslashes(), addslashes(), etc...) to make sure what's being passed could not in any way damage your website. Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-434948 Share on other sites More sharing options...
Norsk.Firefox Posted January 9, 2008 Share Posted January 9, 2008 In theory it ain't possible to manipulate the sessions. Their stored at the server, and just a session id is stored as Cookie. But the userinput is the securityproblem. Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-434957 Share on other sites More sharing options...
kratsg Posted January 9, 2008 Share Posted January 9, 2008 In theory it ain't possible to manipulate the sessions. Their stored at the server, and just a session id is stored as Cookie. But the userinput is the securityproblem. Yes, in theory, but nothing is ever impossible. If there ain't a way, someone will find a way (Murphy's Law). I would remain on the safe side, it takes up what, an extra 5 or 6 lines to re-validate each time? Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-434961 Share on other sites More sharing options...
UbH Posted January 9, 2008 Author Share Posted January 9, 2008 Use sessions and save $_POST as session. session_start(); in top of the three last pages in the two last pages you change $_POST with $_SESSION and as the last thing in the second file you put Code: <?php foreach($_POST as $n => $v) $_SESSION[$n] = $v; ?> This just tell you a simple way to do it, you should try include some type of security. Right off the bat I got these two errors.. Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /mnt/w0209/d31/s33/b02c2dec/www/counselor_of_the_year/nominationSubmit.php: in /mnt/w0209/d31/s33/b02c2dec//www/somewebsite.com/somelocation/anotherlocation/counselor_of_the_year/nominationSubmit.php on line 9 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /mnt/w0209/d31/s33/b02c2dec/www/counselor_of_the_year/nominationSubmit.php: in /mnt/w0209/d31/s33/b02c2dec/www/somewebsite.com/somelocation/anotherlocation/counselor_of_the_year/nominationSubmit.php on line 9 Here is my code for my first nominationSubmit.php script... what am I doing wrong? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta HTTP-EQUIV="REFRESH" content="2; url=http://www.somewebsite.com/somelocation/anotherlocation/counselor_of_the_year/uploadSubmit.php"> </head> <body> <?php session_start(); //Collect Student/Nominator Information $sFirstName = $_POST['sFirstName'];// $sLastName = $_POST['sLastName']; // $sAddress = $_POST['sAddress']; // $sCity = $_POST['sCity']; // $sState = $_POST['sState']; // $sZip = $_POST['sZip']; // $sTelephone = $_POST['sTelephone'];// $sEmail = $_POST['sEmail']; // $sSchool = $_POST['sSchool']; // $sPrincipal = $_POST['sPrincipal']; //Collect Relationship Information $relationship = $_POST['relationship'];// $otherDescipt = $_POST['otherDescipt'];// //Collect Counselor/Nominee Information $cFirstName = $_POST['cFirstName']; // $cLastName = $_POST['cLastName']; // $cDistrict = $_POST['cDistrict']; // $cSchool = $_POST['cSchool']; // $cAddress = $_POST['cAddress']; // $cCity = $_POST['cCity']; // $cState = $_POST['cState']; // $cZip = $_POST['cZip']; // $cYears = $_POST ['cYears']; // mkdir("submissions/2008_2009/$cFirstName$cLastName"); foreach($_POST as $n => $v) $_SESSION[$n] = $v; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-434963 Share on other sites More sharing options...
Norsk.Firefox Posted January 9, 2008 Share Posted January 9, 2008 Yeah, sure what you're telling Google quote_smart and use that function <?php foreach($_POST as $n => $v) $_SESSION[$n] = quote_smart($v); ?> UbH: Session start has to be the first thing in the document.. So you have to put <?php session_start(); ?> before the HTML-code Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-434966 Share on other sites More sharing options...
GingerRobot Posted January 9, 2008 Share Posted January 9, 2008 what am I doing wrong? The call to session_start(); must be sent before any headers. Headers will get sent with the first output to the browser - so the call to the function must be called before any output. In other words, move the session_start() function above everything else including the document type definition. Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-434973 Share on other sites More sharing options...
UbH Posted January 9, 2008 Author Share Posted January 9, 2008 Thanks Norsk.Firefox Kratsg and GingerRobot I have it working now.. email gets sent with veriables intact. I only need help with one more thing. I would like to have a function to check to see if a person/folder has been created on the web server, so in my first nominationSubmit.php script I have just wrote this but its not working.. where would you guys suggest I to fix? //Directory Creation Checking $newDir = 'submissions/2008_2009/$cFirstName$cLastName'; //Create New Submissions Folder if ($newDir = 0) { mkdir("submissions/2008_2009/$cFirstName$cLastName"); } else { echo "Sorry this person has already been nominated"; } Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-434985 Share on other sites More sharing options...
GingerRobot Posted January 9, 2008 Share Posted January 9, 2008 Try: //Directory Creation Checking $newDir = 'submissions/2008_2009/$cFirstName$cLastName'; //Create New Submissions Folder if (!is_dir($newDir)) { mkdir("submissions/2008_2009/$cFirstName$cLastName"); } else { echo "Sorry this person has already been nominated"; } Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-434989 Share on other sites More sharing options...
Norsk.Firefox Posted January 9, 2008 Share Posted January 9, 2008 It wont work, variables don't work inside single quotes Try: <?php //Directory Creation Checking $newDir = is_dir('submissions/2008_2009/'. strlower($cFirstName .$cLastName)); //Create New Submissions Folder if ($newDir == false) { mkdir("submissions/2008_2009/". strtolower($cFirstName$cLastName)); } else { echo "Sorry this person has already been nominated"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-434993 Share on other sites More sharing options...
UbH Posted January 9, 2008 Author Share Posted January 9, 2008 Herm.. GingerRobots Version I get this error is folder has already been created. Warning: mkdir() [function.mkdir]: File exists in /mnt/w0209/d31/s33/b02c2dec/www/somewebsite.com/somelocation/anotherlocation/counselor_of_the_year/nominationSubmit.php on line 42 Norsk.Firefox Version I get this error regardless if a user has been created before or not. Parse error: syntax error, unexpected T_VARIABLE in /mnt/w0209/d31/s33/b02c2dec/www/somewebsite.com/somelocation/anotherlocation/counselor_of_the_year/nominationSubmit.php on line 43 Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-435001 Share on other sites More sharing options...
drummer101 Posted January 9, 2008 Share Posted January 9, 2008 change mkdir("submissions/2008_2009/". strtolower($cFirstName$cLastName)); to mkdir("submissions/2008_2009/". strtolower($cFirstName . $cLastName)); Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-435005 Share on other sites More sharing options...
UbH Posted January 9, 2008 Author Share Posted January 9, 2008 Here is what I have changed the code too.. //Directory Creation Checking $newDir = is_dir('submissions/2008_2009/'. strlower($cFirstName .$cLastName)); //Create New Submissions Folder if ($newDir == false) { mkdir("submissions/2008_2009/". strtolower($cFirstName . $cLastName)); } else { echo "Sorry this person has already been nominated"; } But I am still getting an error regardless if a directory is already created or not. Fatal error: Call to undefined function strlower() in /mnt/w0209/d31/s33/b02c2dec/www/somewebsite.com/somelocation/anotherlocation/counselor_of_the_year/nominationSubmit.php on line 38 Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-435020 Share on other sites More sharing options...
UbH Posted January 10, 2008 Author Share Posted January 10, 2008 Is anyone able to help me with this? Its the last part I need to call this project complete. Thanks everyone for helping me so far!! Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-435101 Share on other sites More sharing options...
drummer101 Posted January 10, 2008 Share Posted January 10, 2008 ... strlower($cFirstName .$cLastName)); the function is strtolower() change that line to $newDir = is_dir('submissions/2008_2009/'. strtolower($cFirstName . $cLastName)); Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-435275 Share on other sites More sharing options...
GingerRobot Posted January 10, 2008 Share Posted January 10, 2008 It needs to be strtolower(): //Directory Creation Checking $newDir = is_dir('submissions/2008_2009/'. strtolower($cFirstName .$cLastName)); //Create New Submissions Folder if ($newDir == false) { mkdir("submissions/2008_2009/". strtolower($cFirstName . $cLastName)); } else { echo "Sorry this person has already been nominated"; } Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-435364 Share on other sites More sharing options...
UbH Posted January 10, 2008 Author Share Posted January 10, 2008 Excellent its working now.. Just one more little thing if I may ask. How do I redirect a person to the previous page or stop the meta tag redirect if the $newDir has already been created and echo's "Sorry this person has already been nominated"? I tried //Directory Creation Checking $newDir = is_dir('submissions/2008_2009/'. strtolower($cFirstName .$cLastName)); //Create New Submissions Folder if ($newDir == false) { mkdir("submissions/2008_2009/". strtolower($cFirstName . $cLastName)); header( 'Location: http://www.somewebsite.com/nextstep.php' ) ; } else { echo "Sorry this person has already been nominated"; header( 'Location: http://www.somewebsite.com/thepreviousepage.html' ) ; } with and also without the meta tag at the top <meta HTTP-EQUIV="REFRESH" content="2; url=nextstep.php"> but all I got was this error: Warning: Cannot modify header information - headers already sent by (output started at /mnt/w0209/d31/s33/b02c2dec/www/somewebsite.com/somepage/anotherpage/counselor_of_the_year/nominationSubmit.php:9) in /mnt/w0209/d31/s33/b02c2dec/www/somewebsite.com/somepage/anotherpage/counselor_of_the_year/nominationSubmit.php on line 49 Thank you ALL for helping me this far I couldn't have done it with out you guys!!! Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-435732 Share on other sites More sharing options...
drummer101 Posted January 10, 2008 Share Posted January 10, 2008 You can't send any HTML or whitespace before you send the headers, IE. all your PHP processing needs to be taken care of before you pass HTML. (although you can do ob_start() to hold the page request and process everything and send it all at once. It will fix the problem, but not the code.) Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-435764 Share on other sites More sharing options...
UbH Posted January 10, 2008 Author Share Posted January 10, 2008 Herm as my title says on the site n00bie, I will have to say HUH? see whats happening is that if the user recives the message "Sorry this person has already been nominated" it still directs them to my third step "The File Uploading Process" instead of shutting down the whole process. From what you are telling me is that I cant do a conditional shut down if they receive the "Sorry this person has already been nominated" message?? If the ob_start() will solve this solution can you provide me with a conditional example of how to use this?? I learn best from example and appreciate all the help you guys have provided so far I have learned a great deal!! Thanks UbH Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-435805 Share on other sites More sharing options...
UbH Posted January 11, 2008 Author Share Posted January 11, 2008 Got it!! Put it in my first line like this: <?php session_start(); ob_start(); ?> And The Rest like this: //Directory Creation Checking $newDir = is_dir('submissions/2008_2009/'. strtolower($Their_First_Name .$Their_Last_Name)); //Create New Submissions Folder if ($newDir == false) { mkdir("submissions/2008_2009/". strtolower($Their_First_Name . $Their_Last_Name)); header("refresh:0; url='uploadSubmit.php'"); } else { echo "Sorry this person has already been nominated"; header("refresh:0; url='index.html'"); } Works like a charm! Thanks drummer101 Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-436093 Share on other sites More sharing options...
drummer101 Posted January 11, 2008 Share Posted January 11, 2008 You're welcome, in the future, try to design your pages so that ALL php is processed BEFORE you even get to <html><head></head> etc... And you'll remove the problem all together. ob_start() is a cheap lazy work around. Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-436096 Share on other sites More sharing options...
UbH Posted January 11, 2008 Author Share Posted January 11, 2008 LESSON LEARNED!!! drummer101 I know you are form helper and have a lot to do but do you think you could help me with one other thing? I created a new topic for it cause this one was getting WAY OFF topic. http://www.phpfreaks.com/forums/index.php/topic,176596.0.html PLEASE I swear I will never bother you again m8 Quote Link to comment https://forums.phpfreaks.com/topic/85259-solved-passing-variables/#findComment-436099 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.