North Posted July 6, 2009 Share Posted July 6, 2009 Here's what I need to somehow do...set a cookie in an included file which comes after another include directive which includes the header. Index.php <?php include "style/head.php"; include $_GET['p'] .".php"; include "style/foot.php"; ?> This demo is for a skeleton of my login script... index.php?p=login will include login.php: <?php if ($_POST['submit'] == 1) { /* Check ... */ if ($success) { setcookie(...); header("Location: /"); } else { /* Display error */ } } else { /* Display the form ... */ } ?> The above code did work until I switched webhosts from one which runs Apache to one which runs CGI. The only "solution" I can come up with here is to check if $_GET['p'] is a login file and then if it is, skip the header include and, instead, include everything inside each of the scripts which need to modify the header. The problem is, about half my files use setcookie() or header() somewhere, and changing that will add a ton of extra code and will mess up the "neatness" factor by a lot.. I'm just looking for some way to actually run the included files first, save the output to something like a variable (something like $var = include "test.php" which, of course, doesn't work) and then print out the output like it did before except this time, by code. Link to comment https://forums.phpfreaks.com/topic/164966-solved-run-include-while-saving-the-output-to-print-out-later/ Share on other sites More sharing options...
North Posted July 6, 2009 Author Share Posted July 6, 2009 I just read about ob_start() and ob_get_contents(). I'm not exactly sure if that's what I'm looking for but if anyone has any other suggestions, please let me know. Link to comment https://forums.phpfreaks.com/topic/164966-solved-run-include-while-saving-the-output-to-print-out-later/#findComment-869892 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.