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? 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']; 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. 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. 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 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. 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() 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? 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. 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? 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
Archived
This topic is now archived and is closed to further replies.