NYCPHP Meetup

NYPHP.org

[nycphp-talk] Returning from Includes

Matt Juszczak matt at atopia.net
Sun Oct 3 15:10:06 EDT 2004


Jose,

Because I have a static main file, module.inc, which I can't modify.  
All that does is check to see if the include file exists, and if it 
does, it includes it.  All my other checks need to be done in the actual 
module include file ... which is why I wanted to include ANOTHER file at 
the top of that that does checks....

Jose Villegas wrote:

> Why don't you check for the user id before you include the file?
>
> if ("ManageUser" == $go)
> {
>     if (!empty($UserID)) include(go.ManageUser);
>     else echo('User ID is missing');
> }
>
> Otherwise I sometimes make includes into functions. This allows me to 
> break from the code at certain points as well as keep track of variables:
>
> function largeIncludedProcess()
> {
>     global $action;
>     global $UserID;
>     etc.
>
>     code, code, code
>
>     $GLOBALS['result1'] = $result1;
>     $GLOBALS['result2'] = $result2;
>     etc.
> }
>
> -jose
> www.josevillegasdesign.com
>
> On Oct 2, 2004, at 2:34 AM, Matt Juszczak wrote:
>
>> Hey all,
>>
>> Just had a quick question.  I've got a system that currently runs 
>> that has a basic module file (module.main) which includes a couple 
>> files...
>>
>> header.html, footer.html, and the current module file .... go.none is 
>> included if $go is NULL, action.none is included if $action is NULL 
>> .... if action is UpdateUserInfo and go is ManageUser then 
>> action.UpdateUserInfo and go.ManageUser is included ... and so on and 
>> so forth.
>>
>> go.* is the text displayed to the screen and UpdateUserInfo is the 
>> include of the action that does updating, deleting, etc....
>>
>> It all works great, except for when someone modifies the URL ... for 
>> instance, changing go from NULL to go equals "ManageUser" .... 
>> go.ManageUser requires a userID, which is hard to check for in 
>> go.ManageUser because it pushes all the code in ....
>>
>> for instance:
>>
>> File go.ManageUser
>>
>> if (!empty($UserID))
>> {
>>     echo "missing";
>> }
>> else
>> {
>>     // 100 lines of code here ... indented... :-(
>> }
>>
>> I could do something else like
>>
>> if (!empty($UserID))
>>     $errors = "Missing file";
>>
>> if (empty($errors))
>> {
>>     // 100 lines of code here
>> }
>>
>>
>> but that still does the indent ... so what i want to do is this:
>>
>>
>> if (empty($errors))
>> {
>>     return; // return from the include
>> }
>>
>> //rest of code here
>>
>>
>> I can't do an exit; because then it won't go back to the main 
>> "module" file and print footer.html, so the page will look messed 
>> up.  Will that single return work though?  What if I wanted to do 
>> multiple layers?  I've tried this and I can't seem to get it working 
>> like i want it to.  Is there a better way?
>>
>> Thanks :)
>>
>> -Matt
>>
>> _______________________________________________
>> New York PHP Talk
>> Supporting AMP Technology (Apache/MySQL/PHP)
>> http://lists.nyphp.org/mailman/listinfo/talk
>> http://www.newyorkphp.org
>>
>>
>
> _______________________________________________
> New York PHP Talk
> Supporting AMP Technology (Apache/MySQL/PHP)
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.newyorkphp.org
>
>
> !DSPAM:415e56fc106731017818960!





More information about the talk mailing list