Jump to content

[SOLVED] Run include while saving the output to print out later


North

Recommended Posts

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.