XpertWorlock Posted July 18, 2008 Share Posted July 18, 2008 Hi, I was wondering whats the proper way of making a session output code? Example below, an if statement? <?php session_start(); $_SESSION['mainData'] = (" if (strlen (".$_SESSION['userNameError'].") > 0) <br><li> echo ".$_SESSION['userNameError']."; "); ?> Instead it outputs : if (strlen () > 0) # echo ; Link to comment https://forums.phpfreaks.com/topic/115351-sessions-and-if-statements/ Share on other sites More sharing options...
MasterACE14 Posted July 18, 2008 Share Posted July 18, 2008 lol, what? why would you even need to do that? Link to comment https://forums.phpfreaks.com/topic/115351-sessions-and-if-statements/#findComment-593042 Share on other sites More sharing options...
XpertWorlock Posted July 18, 2008 Author Share Posted July 18, 2008 sorry I should've explained instead of using a form and having it post back with the error. The error is determined and than saved as a session and the page is reloaded and displaying the error, and than it unsets the session. There is more to the code than that, it's just a lot easier for people to decipher when it isn't a page and a half. Link to comment https://forums.phpfreaks.com/topic/115351-sessions-and-if-statements/#findComment-593045 Share on other sites More sharing options...
Lodius2000 Posted July 18, 2008 Share Posted July 18, 2008 I think you would do <?php if (isset($_POST['field_name'])) { //do errorchecking code // output a sanitized $_POST['field_name'] //if for some reason a sanitized $_POST['field_name'] can not be created, then print an error message and redisplay form } ?> sorry but without knowing your purpose, i cant get more specific, but my example doesnt use and doesnt need sessions EDIT: as long as your form posts to $_SERVER['PHP_SELF'] the page reloads when you hit submit and you dont need to store anything in sessions because it reloads with the values previously submitted in your form Link to comment https://forums.phpfreaks.com/topic/115351-sessions-and-if-statements/#findComment-593046 Share on other sites More sharing options...
XpertWorlock Posted July 18, 2008 Author Share Posted July 18, 2008 $_SESSION['mainData'] = (" if (strlen (".$_SESSION['userNameError'].") > 0) /*<br><li>*/ echo ".$_SESSION['userNameError']."; "); siteLayout(); The Session(mainData) asks an if statement and than outputs. siteLayout() outputs a bunch of stuff including Session(mainData). P.S. Maybe an easier way to ask, how do I get variables to appear/output in sessions. P.S.S. How do I write code into Sessions EXAMPLE OF SITE DESIGN siteLayout() holds all the design of the page and includes empty sessions into the design. for each new page I only have to write the code for the body of the page and nothing else. But now I need to write code into the body. Link to comment https://forums.phpfreaks.com/topic/115351-sessions-and-if-statements/#findComment-593050 Share on other sites More sharing options...
Lodius2000 Posted July 18, 2008 Share Posted July 18, 2008 just store a string including your code in sessions ie $_SESSION['blah'] = "<html>blah blah blah</html>"; echo $_SESSION['blah']; Link to comment https://forums.phpfreaks.com/topic/115351-sessions-and-if-statements/#findComment-593052 Share on other sites More sharing options...
Lodius2000 Posted July 18, 2008 Share Posted July 18, 2008 "for each new page I only have to write the code for the body of the page and nothing else" i did the same thing but made 2 functions, 1 for everything before the body and one for eveerything after BUT if you want your session variables to make up the body code, then when you post a form make $_SESSION['blah'] = $_POST['form_data'], where form_data contains all your code in a string Link to comment https://forums.phpfreaks.com/topic/115351-sessions-and-if-statements/#findComment-593054 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.