PHP include_path issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

PHP include_path issue

Post by diseman »

Hello,

Ran into a problem today while trying to pass a bunch of dynamic variables through a URL to another page.

Kept getting the error about include_path and not being found.

I know I'm editing the proper .ini file 'cause I can see my changes in the php info directly after.

Finally, the only way for me to fix it was to change the ALLOW_URL_INCLUDE in my .ini file, which is a complete cheat and very temporary. You can see it below. So, knowing the URL method works, makes me think I haven't been entering a proper path in the "include_path" section of my .ini file.

Here is my directory if it helps with any ideas:

CLGi (top folder)

-----> _includes

--------------->email (sub-folder to _includes)

-----> modules

-----> templates


I had to run this code below from a file in MODULES to make it work, but it's not a long-term solution:

Code: Select all


include ("http://localhost/CLGi/_includes/email/welcome.php?resend_welcome_email&b_first_name=".$b_first_name."&b_last_name=".$b_last_name."&users_id=".$_SESSION["users_id"]."&account=".$account."&username=".$username."&company_name=".$affiliate."&sub_domain=".$sub_domain."");

I'm on a Windows 10 machine. I would prefer to update the .ini file rather than set the path in any file.

I'm confused about PEAR. Is this something I have to have to fix this problem? Do I need PEAR at all?

I'm using UniServer Zero XI for my local server.

I've looked at dozens of online help, but nothing seems to work.

Any help would be greatly appreciated.

Thank you!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP include_path issue

Post by Celauran »

Include files by path, not by URI. That said, what are you trying to accomplish here? You also don't typically include GET parameters in included files.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP include_path issue

Post by Celauran »

I'm confused about PEAR. Is this something I have to have to fix this problem? Do I need PEAR at all?
I'm not sure where that enters into this discussion, but PEAR used to be used for pulling in third party code but has been superseded by Composer.
User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

Re: PHP include_path issue

Post by diseman »

Celauran wrote:Include files by path, not by URI. That said, what are you trying to accomplish here? You also don't typically include GET parameters in included files.
ok, good. I can work with that since I suspected the variables in the include file were the problem. I once took them out and ran it again and I got what was expected.

So, if I'm in MAIN1.php and I get to a point down the file where I want to run a script that is named MAIN2.php in a different dir., BUT want to remain on the MAIN1.php page, how is that done that also allows for including GET variables.

What I read on the web today told me it was the way to do this. In fact, I saw several examples showing the same procedure, which is what I posted?

I tried header... but that takes me to another page and I don't want to leave Main1.php.

Basically, just need to stay put and run a script from where I'm at.

Thanks
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP include_path issue

Post by Celauran »

Any variables defined in main1 will be available in main2 once it has been included. This still doesn't sound like a good idea, though. Take whatever main2 is doing, wrap it in functions, and call those functions. Reusable and less chance of side effects.
User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

Re: PHP include_path issue

Post by diseman »

k, so taking out all the variables and just having:

Code: Select all


include ("../_includes/email/welcome.php?resend_welcome_email");

causes this again, which is a problem I've been having the past few hours:

[syntax=php

Warning: include(../_includes/email/welcome.php?resend_welcome_email): failed to open stream: No error in C:\Users\Dirk\Documents\My-Server\www\CLGi\modules\applicant_control_panel.php on line 50

Warning: include(): Failed opening '../_includes/email/welcome.php?resend_welcome_email' for inclusion (include_path='C:\Users\Dirk\Documents\My-Server\www\CLGi\_includes') in C:\Users\Dirk\Documents\My-Server\www\CLGi\modules\applicant_control_panel.php on line 50

][/syntax]

looking at the function advice now.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP include_path issue

Post by Celauran »

You don't want that query string in there at all. If welcome.php needs that query string to work, that's a good indication that this needs some better abstraction. As you work with PHP more, you will naturally move from page scripts to functions to classes. This is an example of why.
User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

Re: PHP include_path issue

Post by diseman »

when we talk about include_path in .ini file, are we talking about where MY _includes directory is located or some other 'include' folder that might belong to PHP, PEAR, or something else I don't know about?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP include_path issue

Post by Celauran »

User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

Re: PHP include_path issue

Post by diseman »

Thanks Celeraun. Your tip about the include file was the fix. The way I was using it was causing the problems. I've been avoiding classes 'cause it seems difficult concept, but your suggestion about it got me to think about it in a different way. Then, when google'ing it, it made a little more sense.

I'm in a little bit of information overload, but I'm in no hurry

thank you again.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP include_path issue

Post by Celauran »

It's hard to wrap your head around initially. What helped make it click for me was the transition first to using functions in the global namespace. I'd see some functionality that was being repeated across scripts, which just felt inefficient. Making changes to one means making changes to basically the same code in a number of places. This naturally led to looking into wrapping code in functions for ease of modification and reuse. Once you do that you start seeing little abstractions you can make to remove duplication across similar functions to make them into one. You then end up with a whole mess of functions, which you naturally start grouping based on what they're used for. At this point, you've understood classes even if you haven't implemented them. All of that to say, you don't have to go 100% procedural straight to 100% OOP. A little at a time will ease the pain of transition, make learning easier, and in my case at least, make the lessons stick better.
Post Reply