php class autoload - seems to be caching? - php

I've recently implemented the following code to autoload classes in my php code:
function my_autoloader($class) {
include 'classes/class_' . $class . '.php';
}
spl_autoload_register('my_autoloader');
The code is contained in file that gets included at the top of all files that need to generate a web page. So then I set about removing the require_once calls from my code. Here's an example:
require_once('classes/class_web_page.php');
As you'll probably gather from the above, the various pages on my site (it's an online community so there's a forum, gallery, etc) all use the web_page class to generate page headings, menus, etc. The various pieces of code create a web_page object, set various parameters to determine what menu options etc are needed, give the page some content, and generate the html.
All seemed well until I made a change to the class_web_page.php file. The change was immediately apparent on most of the site... except for the home page.
I refreshed my browser, switched if off an on again :-) tried calling http://www.terragenesis.co.uk/index.php rather than just http://www.terragenesis.co.uk/, and even stopped and restarted apache on the server. Despite all this the changes didn't show on the home page. In the end I put the require_once line back into index.php... and presto hey: the changes I'd made in class_web_page.php appeared on the home page.
So it looks to me like the autoloader was loading a cached copy of class_web_page.php and nothing, not even restarting Apache, was going to persuade it to get the new version. Why it should do this for the home page and not the other pages... I have no idea.
Has anybody else experienced this? Have I done something wrong with the autoloader code? How can I fix it... or am I going to have to put all the require_once statements back in place? :-(
My server has PHP version 5.1.6

I found the answer to this... and as usual with "bugs" that elude me for days, it turns out that I did something incredibly stupid:
It turns out that at some point in the past I accidentally uploaded a copy of class_web_page.php into the site home directory rather than the classes subdirectory. So it existed twice.
So, it would appear that despite my autoloader telling php to look in the classes subdirectory, it will look first in the same directory as the main script (index.php in the case of my site's home page). All of the other site page scripts are in subdirectories (forum, gallery, etc) so they were "correctly" using the /classes/class_web_page.php
I've now deleted the copy of class_web_page.php that was living in the home directory... and everything works as it should.

Are you sure that this file is actually loaded (or a cached version of it)?

Related

How to move Joomla's configuration.php file above the root folder in a web host?

I have installed a security solution in my Joomla website,and it's suggest that to put the configuration.php file above the Public_html Folder,how could it be possible?
how to tell the CMS to recognize the new location?
is the solution would be valid in all versions of the Joomla CMS? ,if it's not,so please
write:
1st:Joomla 2.5 Solution.
2nd:Joomla 3 Solution.
you would need to modify the defines.php file located in the includes folder.
Specifically this line:
define('JPATH_CONFIGURATION', JPATH_ROOT);
And change JPATH_ROOT to the correct path.
But the problem with this is that you are modifying a core file so if an update changes the defines.php file it will overwrite your changes and will break your setup. You will need to reedit the file.
Also the JPATH_CONFIGURATION constant may be used for other things within the CMS that are not specifically trying to get the configuration.php file so make sure to check that it will not adversely affect other parts of the cms before doing this in production.
Alternatively you can change the frameworks.php file (also in the includes folder) directly to change from where the configuration is loaded from
ob_start();
require_once JPATH_CONFIGURATION . '/configuration.php';
ob_end_clean();
Just change the require_once line to the correct path.
Again since this is a core file it could be changed by an update. But this may also affect other parts if the config file is loaded manually in components or other parts of the cms.
Simply answer is don't do it. This would mean you would have to do what #Patrick has suggest which is correct and will work, however it means editing a core Joomla file. This is not a good idea as in your case, if you ever update Joomla, you will have to perform this change every time and it you forget (which is likely), your site will stop working completely.
I would strongly suggest you find a different "security solution" which does not involve having to modify any core Joomla files.
If you could define what you mean by "security solution", then maybe an alternative could be provided for you
I didn't dig for 'since when this has been implemented', But it can be done without changing the core.
Joomla looks for a defines.php in the root and if its present, imports it. And then if it finds a constant named _JDEFINES defined, it doesn't load the original file, effectively overriding it completely.
So, If you wish to override the defines its pretty easy and all you have to do is copy the contents of the defines.php file from under the webroot/includes/ path and paste it inside the one we created in the webroot. And you can change the following constant as per your taste.
define('JPATH_CONFIGURATION', JPATH_ROOT."/my/supersecret/directory");
Now there is one more thing left to be done and then we are good to go :)
You have to prepend the following lines to the top of our override file (the defines.php in the webroot).
define('JPATH_BASE', __DIR__);
define('_JDEFINES', 1);
This constant conveys to the framework that the defines have been overridden and to use the new file accordingly (Last time I checked, this flag/constant is checked at around 10 different places all over the framework eg. here, so its important)
Also I have seen this feature available with Joomla v2.5.0 and v3.8.8 as per your requirements in the question.
Edit: Remember you have to repeat the same procedure for administrator folder too if you want admin panel to work, and remember that administrator has its own /includes/defines.php

Connect an directory index to another directory index

I'm trying to call my index.php on my cPanel, however since my hosting service only allows up to 1 sublevel of directory, I have to bring up my index.php.
I'm using Yii framework, and since it's my first application. I dont know how to link it. I also just continued the application from another developer, it's making me confused on how to change or place my index.php
Is it possible to create an index.php to call another index.php, since the current index.php, still has to run the yii framework? I dont want to change the directory paths since there's just too many paths to change.
UPDATE:
Found out I was inputting the wrong path, I've got it to show the page, but now it does not load any of the images/css. What's seems to be the problem now?
I might be asking a dumb question, but have you tried a PHP Include? This won't affect paths or anything, but the code from the included index.php will be used in the first page...
<?PHP
include_once('directory/index2.php');
?>

Installing Zend Gdata Client library

Hi this is my first post on here. I am trying to install the Gdata Zend Client library without much success.
I have used these resources + scoured Stack Overflow.
https://developers.google.com/gdata/articles/php_client_lib
http://jeromejaglale.com/doc/php/google_calendar_api
I want to be able to add,edit etc events on google calendar via PHP. My problem/question is i really dont understand what the include_path settings are all about and how to set them in order to make the class work. Of course i checked php manual regarding this but still draw a blank.
I have downloaded the relevant class and uploaded it to my web root. In the past i would just include a class by using php include at the top of the page and this would suffice.
I am of the understanding that i need to change the php.ini file to show php where my class is. Does this mean that i have to put my class somewhere else other than the web root.
I am terribly confused about this step and i know that if i can get it installed, actually using the class should be relatively easy.
Thanks for any help.
Welcome! Your Q is about include files rather than ZF elements.
Understanding where the include setting can be made (and subsequently overridden) is an absolute key bit of information.
You need to find out where it is on the server you are working on.
echo ini_get('include_path');
Then dash off and really, really read the corresponding manual page.
Try out including a very simple file with an echo statement, and you will regain your sanity and confidence.
http://www.php.net/manual/en/function.include.php
Get that working then have a play with this:
http://www.php.net/manual/en/function.ini-set.php
The experience how you can include a file from the same directory (not generally a good idea if that is a public webpage - inside your webroot)
Then if you want to really chase this thing down, look at where you can set this in Apache and per-directory in .htaccess files.
Finally, you can just include a file by telling include/require the exact path from the top of the tree;
include /var/www/includes/libraries/and/so/on.php;
There are SO many places you can set and override this that you are really best off finding out where the server thinks the include directory is and putting your compoenents in there:
Now, when that comes to ZF stuff, I (on Deb and Ubuntu anyhow) put the contents of
Zend Framworks version XYZ ZendFramework/lib/Zend <-that folder into:
/usr/share/php/Zend <-into this place
Then setup your autoloader and Robert is your mothers brother...
Zend/Gdata.php line 124 is like this:
public static function import($uri, $client = null,$className=’Zend_Gdata_Feed’)
Change that to this:
public static function import($uri, $client = null,$className=’Zend_Gdata_Feed’, $useObjectMapping = true)

How to use IntelliJ Liveedit with php include

I've been working on a webpage and I wanted to break it out into templates that I could pull in. For example the navbar is common to all of the webpages so it gets pulled in like this.
<?php include("templates/navigationBar.html"); ?>
As soon as I move the code out of the index.php into the templates directory IntelliJ LiveEdit plugin stops updating the main index.php (that's including stuff from the templates directory) when I make changes to one of the templates.
I figure this is because the IntelliJ IDE is "stupid" and will only tell the plugin to refresh the page when it exactly matches the page I'm working on. Is there any way to map those notifications from my templates folder into any php file that might include them?
http://confluence.jetbrains.com/display/WI/LiveEdit
http://plugins.jetbrains.com/plugin/?null&pluginId=7007

Magento block template file not loaded

I'm trying to do something very basic: edit a small part of the category product pager template. I copied pager.phtml from .../base/default/template/page/html/ into my own theme's template/page/html folder and changed what I needed changed in the new file. Unfortunately, nothing is changed on the frontend.
I've tried enabling "Template Path Hints" and it definitely shows my custom template being loaded. When I blank out my theme's pager.phtml, all the content stays (as if its still loading the default template). When I edit the default template, still nothing changes! Ah ha! It must be cached...
But I've got the caches disabled (its a development site) and tried refreshing them all anyway. Nothing changes. I've edited many a template on this site and they've all worked as expected, its only pager.phtml that is giving me trouble.
If anyone could point me in the right direction or even toss a few more debugging ideas my way, that would be great. Thanks in advance.
Tripple check the paths. Seriously, something about working with Magento makes people (myself included) miss things that are one level below the obvious.
Once you've done that, jump to
app/code/core/Mage/Core/Block/Template.php
Find the lines that include the template file
$includeFilePath = realpath($this->_viewDir . DS . $fileName);
if (strpos($includeFilePath, realpath($this->_viewDir)) === 0 || $this->_getAllowSymlinks()) {
include $includeFilePath;
} else {
Mage::log('Not valid template file:'.$fileName, Zend_Log::CRIT, null, null, true);
}
and add debugging code to figure out why your phtml isn't being included.
If your caches are off, and you editing the base/default package/theme has no effect, it sounds like you are editing the wrong file ...
By chance is it a 1.3 template on a 1.4 build - as the pager set-up changed between the two versions and would lead to peculiar issues like you are describing.
Have you tested overriding another .phtml file to see if it actually works (ie. if you have set it up correctly).
Finally, caching being the last resort, have you got APC/Eaccelerator installed with the mtime/stat parameter set to false? As this would ignore the file modified time and serve up data directly from its internal cache. An Apache/PHP restart would prove this.
Verify by running
php -i | grep mtime
php -i | grep stat
Or by creating a test phpinfo(); file
Check your design settings in System->Config->General->Design->Package (example: default)
System->Config->General->Design->Themes->Default (set your theme directory name).
Also try:
Reindexing (the template may be changed, but the old index may be loaded)
clean /var/cache folder itself.
Is the site using litespeed or any other caching utility? May have to clean those caches as well.

Categories