PHP Circles

I’m sure no one remembers a while back that I started reworking a website using PHP includes to call in common content rather than change menus, news and promotions on every page by hand. Well, now it has come back to bite me on the butt.

I have a couple of form pages that use PHP to process the form, route email notifications, and pass data to the success/fail pages… The success or failure pages are not processing their own PHP includes along with the data sent by the forms, leaving blanks where the includes should be. Here’s the form code responsible for finding the success page and populating it with the form variables:

http://pastie.org/210470

The resulting success page processes the forwarded form data, but fails to process its own PHP includes (I know the file in the pastie is .html, but same happens if it’s .php).

I’m so tired, I just need someone else to look at this and say “No wonder, you forgot to __________ the _______________”.

Ernie Simpson – thebigerns


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

“No wonder, you forgot to __________ the _______________”.

Oooh, I love MadLibs! Let’s see now… :wink:


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Looks OK Ernie, anyway… just did a test on my server and it works as
expected there, so… are you sure there * are * contents to upload-
success.html? I know, I am sure there is but as it all works OK for me
I thought I would ask! or is the path correct? some servers will not
throw an error when this happens so maybe…

The other thing you might try is replace the upload-success.html with
just some text like ‘Hi there’ and see if it loads then, or remove
upload-success.html and see if the script throws the error on
if (file_exists($FileSuccessPage) === false) {
which would then at least tell you the path is right.

HTH
Mike

On Jun 6, 2008, at 11:41 PM, The Big Erns wrote:

I’m sure no one remembers a while back that I started reworking a
website using PHP includes to call in common content rather than
change menus, news and promotions on every page by hand. Well, now
it has come back to bite me on the butt.

I have a couple of form pages that use PHP to process the form,
route email notifications, and pass data to the success/fail pages…
The success or failure pages are not processing their own PHP
includes along with the data sent by the forms, leaving blanks where
the includes should be. Here’s the form code responsible for finding
the success page and populating it with the form variables:

http://pastie.org/210470

The resulting success page processes the forwarded form data, but
fails to process its own PHP includes (I know the file in the pastie
is .html, but same happens if it’s .php).

I’m so tired, I just need someone else to look at this and say “No
wonder, you forgot to __________ the _______________”.

Ernie Simpson – thebigerns


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

If I understand the problem correctly, you are trying to include a file that has code in it, and you need that code in the include to render before you do more things to it with string replacement. Try this, instead of using fread to load your string variable. I believe this will work, it’s the basis of one of my template engines.

function render_static($strFilePath){
    if(file_exists($strFilePath)){
        ob_start();
        extract($GLOBALS);
        include($strFilePath);
        return ob_get_clean();
    }
    return false;
}

This function will return a string containing the rendered value of the file you pass to it. Any current global variables (current as of the point in the script where the function is called) will be substituted in that file before the replacement is returned.

//template.php
<div id="complaint">
<p>Pardon me, but your
<?=$thing_1?>
just <?=$verb?>
my <?=$thing_2?></p></div>

In another file:

$file = '/path/to/template.php';
$thing_1 = 'dog';
$thing_2 = 'loafers';
$verb = 'peed on';
$rendered = render_static($file);

I hope this helps, I’m still not sure I’m solving the correct problem for you.

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Mike –

What I have is a PHP form script which passes form data to the success
page. I also have PHP scripts to process in the success page (the
includes).

Screenshot of success page accessed via direct url:
http://www.thebigerns.com/myproof/Assets/direct.jpg

Screenshot of success page accessed via PHP form script:
http://www.thebigerns.com/myproof/Assets/form.jpg

So I think I’m having post-processing issues, which gives me some
ideas. Probably the wrong ideas, but that’s at least a start.


Ernie Simpson – Freeway 5 Pro User – thebigerns.com


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Ernie, did you get my idea? I think that might help you. It looks like your post processing is actually working, in that the form values are going in there. But when you acquire the contents of a file with fread() or file_get_contents(), you are not passing that file through the PHP interpreter, so any script elements that are present in it will not be executed in any way.

Using include will execute them, but will do so at the moment that they are included, using whatever variables happen to be hanging around at the time.

The render() function I posted works around that using an output buffer – it sets up an environment inside the function that is isolated from the rest of the script, feeds in a current snapshot of the global variables at the moment that the function is invoked, and then includes the file, which gets all of its variables replaced with those values, and returns the result.

By the way, that’s a very nice looking site!

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walter – I did get your idea, but I found a different solution…
I had uploaded the form.php file to the Resources folder – and set
the form action to Resources/form.php – worked well as long as target
page was html extension.

By uploading the script file to the same level as the new target.php
page, the form data is inserted AND the target.php is properly
processed. How simple was that!

I’ve added your code to my stack of “keepers” to try and work into the
Next Big Thing… as getting scripts to jump in and out of directories
is not my bag, apparently. Thanks for the effort, and for your kind
words about my little project :slight_smile:

On Fri, Jun 6, 2008 at 5:54 PM, waltd wrote:

Ernie, did you get my idea? I think that might help you. It looks like your post processing is actually working, in that the form values are going in there. But when you acquire the contents of a file with fread() or file_get_contents(), you are not passing that file through the PHP interpreter, so any script elements that are present in it will not be executed in any way.

Using include will execute them, but will do so at the moment that they are included, using whatever variables happen to be hanging around at the time.

The render() function I posted works around that using an output buffer – it sets up an environment inside the function that is isolated from the rest of the script, feeds in a current snapshot of the global variables at the moment that the function is invoked, and then includes the file, which gets all of its variables replaced with those values, and returns the result.

By the way, that’s a very nice looking site!


Ernie Simpson – Freeway 5 Pro User – http://www.thebigerns.com/freeway/


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options