wob_b Posted September 27, 2009 Share Posted September 27, 2009 Im try to make a page which does something when its opened with some posted variables, and then saves the page outted as a session, so that if its opened without anything posted it shows the same page it did last time. How can i do this? Quote Link to comment https://forums.phpfreaks.com/topic/175718-solved-retrieve-the-outputted-page/ Share on other sites More sharing options...
Alex Posted September 27, 2009 Share Posted September 27, 2009 I'm not exactly sure what you mean.. Do you mean something like this? <?php session_start(); if(isset($_POST['var'])) $_SESSION['var'] = $_POST['var']; if(isset($_SESSION['var'])) echo $_SESSION['var']; Quote Link to comment https://forums.phpfreaks.com/topic/175718-solved-retrieve-the-outputted-page/#findComment-925970 Share on other sites More sharing options...
wob_b Posted September 27, 2009 Author Share Posted September 27, 2009 no. I want to run a line at the end of the php file, which will get the html source code to the page ive just outputted, and then save that as a session. Quote Link to comment https://forums.phpfreaks.com/topic/175718-solved-retrieve-the-outputted-page/#findComment-925979 Share on other sites More sharing options...
Alex Posted September 27, 2009 Share Posted September 27, 2009 Oh, I see. Well you can do something like this: <?php session_start(); ob_start(); echo <<<END All your page's output here END; $_SESSION['var'] = ob_get_contents(); ?> $_SESSION['var'] will then include everything that was output on the page. Quote Link to comment https://forums.phpfreaks.com/topic/175718-solved-retrieve-the-outputted-page/#findComment-925984 Share on other sites More sharing options...
wob_b Posted September 27, 2009 Author Share Posted September 27, 2009 perfect, thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/175718-solved-retrieve-the-outputted-page/#findComment-925987 Share on other sites More sharing options...
redarrow Posted September 27, 2009 Share Posted September 27, 2009 alex never seen ob_start() after the session_start is that new? sorry i get it works with the ob_start(); then ob_get_contents to get what in between the two functions. Quote Link to comment https://forums.phpfreaks.com/topic/175718-solved-retrieve-the-outputted-page/#findComment-925991 Share on other sites More sharing options...
Alex Posted September 27, 2009 Share Posted September 27, 2009 alex never seen ob_start() after the session_start is that new? sorry i get it works with the ob_start(); then ob_get_contents to get what in between the two functions. ob_start() isn't related to session_start(), ob_start() is just to turn output buffering on so that you can catch all the output of the page and set it to a session variable later on through ob_get_contents(). Check them out, ob_start(), ob_get_contents() Quote Link to comment https://forums.phpfreaks.com/topic/175718-solved-retrieve-the-outputted-page/#findComment-925994 Share on other sites More sharing options...
redarrow Posted September 27, 2009 Share Posted September 27, 2009 but , if ob_start() dose not go before the session_start() user's still get there errors. that because they got HTML or wight spaces before session_start() i guess? Quote Link to comment https://forums.phpfreaks.com/topic/175718-solved-retrieve-the-outputted-page/#findComment-925999 Share on other sites More sharing options...
Alex Posted September 27, 2009 Share Posted September 27, 2009 but , if ob_start() dose not go before the session_start() user's still get there errors. that because they got HTML or wight spaces before session_start() i guess? It doesn't matter either way because ob_start() doesn't output anything (So you won't get a headers already sent error if you call ob_start() first). So.. session_start(); ob_start(); or ob_start(); session_start(); There will be no difference. Quote Link to comment https://forums.phpfreaks.com/topic/175718-solved-retrieve-the-outputted-page/#findComment-926001 Share on other sites More sharing options...
redarrow Posted September 27, 2009 Share Posted September 27, 2009 Thank you very interesting? Quote Link to comment https://forums.phpfreaks.com/topic/175718-solved-retrieve-the-outputted-page/#findComment-926003 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.