FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Nested PHP
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Nested PHP [message #184872 is a reply to message #184866] Wed, 12 February 2014 12:14 Go to previous messageGo to previous message
Stefan+Usenet is currently offline  Stefan+Usenet
Messages: 3
Registered: June 2013
Karma:
Junior Member
On Wed, 12 Feb 2014 11:13:04 Adrian Tuddenham wrote:
>>>> > Might be worth trying writing to a temporary file, include()ing
>>>> > it, then cleaning up at the end of the script. It's a LITTLE
>>>> > complicated, but...

>>>> And subject to all kinds of problems - such as concurrency with
>>>> others requesting the same page, getting rid of old copies, having
>>>> to redirect the browser to the temporary file, the user bookmarking
>>>> the temporary file... and probably several others.

> How do you delete the file? I have tried a few 'obvious' (obvious to
> me, that is) methods, but they don't seem to work. I initially tried
> going down the temporary file route, but my inability to find a way of
> deleting the files was one reason why I abandoned it.

If you do something like:

-----------------------------------------
<?php

$file = tempnam('/tmp/', 'tmp');
$handle = fopen($file, 'w');
fwrite(
$handle,
'<html><body><p><?php echo "hello world"; ?></p></body></html>'
);
fclose($handle);

include $file;

unlink($file);

?>
-----------------------------------------

....then this is quite safe (one could create a race condition by
guessing the temporary filename and opening it in another process,
but this cannot be done from the outside and is thus IMHO rather
neglectible) and does what it should do.

But:

>>> The big question, though, is why can't this be solved WITHOUT the
>>> clunky mechanism. It almost smells richard-ish...

That's the point. Even though the code above works, it is ugly and
very difficult to maintain. I would use it as a base for fun programs
and brainteasers ("read in the current program file, modify it, write
it out with a different name and include it" comes to my mind), but
definitely not for real world applications.

> Sorry if my beginner's questions sound like that, but I have started
> trying to teach myself php from a position of almost complete ignorance,
> especially in the way servers work. My previous experience of using a
> 'server', if you can call it that, was programming in AlgolW under
> Multics on an ICL System 4 mainframe in the 1970s; what little
> programming I have done since then has been on desktop machines.

No problem with that. It's just that most things *can* be done in a much
easier way nowadays and therefore *should* be done that way.

Bye,
Stefan

--
http://kontaktinser.at/ - die kostenlose Kontaktboerse fuer Oesterreich
Offizieller Erstbesucher(TM) von mmeike

Die letzte Steigerungsform von "super", oder warum Stefan so massgebend eifert!
(Sloganizer)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Filling an array with random input doesn't quite work
Next Topic: string length
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 04:00:33 GMT 2024

Total time taken to generate the page: 0.03960 seconds