MAMP include error wp-blog-header.php - wordpress

I'm trying to use the global $wpdb in a plugin to insert data into one of my tables.
From the docs it sounds like I just need to include wp-blog-header.php
However when I try to do so I'm getting an error.
PHP Fatal error: require() [function.require]: Failed opening required 'http://localhost:8888/blog/wp-blog-header.php' (include_path='.:/Applications/MAMP/bin/php/php5.3.6/lib/php') in /Applications/MAMP/htdocs/blog/wp-content/plugins/pluginname/submit/pick.php on line 4
My pluginname/submit/pick.php (which is called by AJAX) has the following code
<?php
$p = 'http://localhost:8888/blog/wp-blog-header.php';
echo $p;
require($p);
echo 'hi';
?>
If I load the pick.php, I see http://localhost:8888/blog/wp-blog-header.php and that is it. So it must be failing on the require, as the error log confirms.
The path is correct as I inserted a quick echo into wp-blog-header.php, and copy pasted the output from pick.php into the address bar and it worked.
Any help would be appreciated.

You don't include php files via urls. What you'll be including is the EXECUTED OUTPUT of the script. Since it's a full-blown url, there's no difference between your internal require() and someone hitting that url with a browser. All you'll get is the output of the script, which is probably blank/nothing.
Including via urls, even if it's just a local request to your own server, opens a whole can of worms in terms of security holes.
Any reason you can't simply include it via a normal local file request, e.g.
require('blog/wp-blog-header.php');
?

Related

Can't enter in my wordpress localhost, getting errors because of custom plugin

I uploaded custom plugin in my wordpress localhost,
after I activated it I've got an error:
Fatal error: Cannot redeclare true_plugins_activate() (previously declared in /Applications/MAMP/htdocs/wordpress/wp-includes/functions.php:7406) in /Applications/MAMP/htdocs/wordpress/wp-includes/functions.php on line 7465
Fatal error: Uncaught Error: Call to undefined function wp_kses_normalize_entities() in /Applications/MAMP/htdocs/wordpress/wp-includes/formatting.php:4333 Stack trace: #0 /Applications/MAMP/htdocs/wordpress/wp-includes/class-wp-fatal-error-handler.php(190): esc_url('https://wordpre...') #1 /Applications/MAMP/htdocs/wordpress/wp-includes/class-wp-fatal-error-handler.php(147): WP_Fatal_Error_Handler->display_default_error_template(Array, false) #2 /Applications/MAMP/htdocs/wordpress/wp-includes/class-wp-fatal-error-handler.php(52): WP_Fatal_Error_Handler->display_error_template(Array, false) #3 [internal function]: WP_Fatal_Error_Handler->handle() #4 {main} thrown in /Applications/MAMP/htdocs/wordpress/wp-includes/formatting.php on line 4333
Then I deleted this plugin, but anyway I can't enter because of this errors.
I tried to rename plugins folder to plugins_old, plugins.deactivate and etc., but nothing.
Also I entered inside phpmyadmin in options and active_plugins and replace everything with this a:0:{}, but nothing changed.
Can you help me, please?
So we discussed the issue somewhat in the question comments (this is the most important note for context)
Whatever happened here is a reflection of a corrupted WordPress install, not a plugin (even if this was the trigger). People have got these errors when upgrading WordPress or PHP [...] [but] I don't think that [true_plugins_activate] function should even be there once.
Someone also had this problem due to installing a plugin called "Monitization", which was malware.
So I'll say what I'd do in this situation.
I would open the functions.php file (in the folder wp-includes) in a text editor, search for "true_plugins_activate" and look inside the contents for any PHP files I didn't recognise. This would only give me information as to whether something unfamiliar (like malware in the plugin with a different name) was involved, but it's clear you know which plugin caused this.
Then, I would reinstall the wordpress files that are corrupted. I would find the version of WordPress that I had installed, then I would download the zip file from https://wordpress.org/download/releases/, extract it, then first copy the two files that show in the error, replacing the originals in wp-includes. I would check if this fixes the problem. Even if it does, I would most likely copy over all the other files. (I might move any plugins or themes I had installed to a separate location, so that they don't get overwritten.)
If I was feeling very investigative, before copying, I would do a diff check of my entire WordPress installation with the WordPress download to see exactly what files were different and how. There are many programs that can do this.
You said that everything was fine after removing both "true_plugins_activate"s, but I would not come to this conclusion so fast, because there was another error in the log that affected a totally different file, wp-includes/formatting.php. I would definitely reinstall multiple or all WordPress files after this.

Module socket not found lua

I am trying to use lua to access redis values from nginx. When i execute lua files on command line there everything is ok i am able to read and write values to redis. But i when try to execute the same files from nginx by accessing a location in which access_by_lua directive is written the following error logged in error log file
no field package.preload['socket']
no file '/home/sivag/redis/redis-lua/src/socket.lua'
no file 'src/socket.lua'
no file '/home/sivag/lua/socket.lua'
no file '/opt/openresty/lualib/socket.so'
no file './socket.so'
no file '/usr/local/lib/lua/5.1/socket.so'
no file '/opt/openresty/luajit/lib/lua/5.1/socket.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
What is the reason for this and how can i resolve this?
In my case I just needed to install the lua-socket package, as the socket library is not built into the default Lua installation like it is in some other languages.
You get this error because your code executes the command require("socket")
This command will search for a file with that name in several directories. If successful the content will be executed as Lua code. If it is not successful you'll end up with your error message.
In order to fix this you have to add the path containing the file either to the system variable LUA_PATH or you have to add it to the global table package.path befor you require the file.
Lua will replace ? with the name you give to require()
For example
package.path = package.path .. ";" .. thisPathContainsTheLuaFile .. "?.lua"
Please read:
http://www.lua.org/manual/5.3/manual.html#pdf-require
https://www.lua.org/pil/8.1.html

DOMDocument->load external entity fail for local file with PHP-FPM

The following PHP "failed to load external entity", even though it is trying to load a local XML file:
<?php
$path = "/usr/share/pear/www/horde/config";
#libxml_disable_entity_loader(false);
$dom = new DOMDocument();
$v = $dom->load($path . '/conf.xml');
echo "status = ".($v?'success':'error')."\n";
?>
The basic question is how can this be fixed?
Log file:
2014/03/10 20:07:10 [error] 26117#0: *24 FastCGI sent in stderr: "PHP message: PHP Warning: DOMDocument::load(): I/O warning : failed to load external entity "/usr/share/pear/www/horde/config/conf.xml" in /usr/share/nginx/html/test.php on line 5
PHP message: PHP Stack trace:
PHP message: PHP 1. {main}() /usr/share/nginx/html/test.php:0
PHP message: PHP 2. DOMDocument->load() /usr/share/nginx/html/test.php:5" while reading response header from upstream, client: x.x.x.x, server: example.com, request: "GET /test.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "example.com"
Uncommenting the libxml_disable_entity_loader line works, but this is not an acceptable solution for a few reasons, e.g. it is systemwide for php-fpm.
Running the PHP from shell returns "status = success". Doing a file_get_contents and then $dom->loadXML($string) also works (i.e. file exists and not a permissions issue). This might be an acceptable workaround, but shouldn't be necessary and doesn't explain why the error is occurring.
The XML file itself is the Horde config, but the problem does not seem to be the contents of the file, since it also occurs with this XML content:
<?xml version="1.0"?>
<configuration></configuration>
Environment is php and php-fpm 5.3.3, nginx 1.4.6, libxml2 2.7.6. My first guess is something to do with php-fpm, but I can't find any config setting that affects this. Any pearls of wisdom appreciated!
EDIT TO ADD
Restarting php-fpm causes it to work briefly. Disabling APC did not seem to help. Seems like something with php-fpm - but what?
FURTHER TESTING
Some additional info:
I tried hitting the server repeatedly, and get an error about 80% of the time. The pattern isn't random - a few seconds of successes followed by a series of errors;
I added a phpinfo() to the end of the above php and doing a diff on the success and failure runs - there is no difference;
If I put libxml_disable_entity_loader(true), I seem to always get an error, which suggests that bug #64938 is at work.
It seems that I need to find why the XML is considered to have external entities.
I think that, if the external entity loader is disabled, it should be obvious that external entities can't be loaded. The only solution is to enable loading of external entities with libxml_disable_entity_loader(false). Since this setting is not thread-safe, I can see two approaches:
Enable it globally and use some other feature to prevent loading of unwanted entities (typically from a network):
Register your own entity loader with libxml_set_external_entity_loader. I think that's the safest solution.
Use the parse option LIBXML_NONET. This should be enough if you simply want to disable network access of libxml2. But you have to make sure to always pass it to calls like DOMDocument::load.
Use locks to protect calls to libxml_disable_entity_loader. This is probably impractical and potentially unsafe.

Wordpress error after upgrade "cannot redeclare" + "eval()'d"

Getting this error after a forced wordpress upload (I was working in the database when at one point of time I got an alert - while on the backend, with only one option to upgrade to the newer available version):
Fatal error: Cannot redeclare _421736532() (previously declared in /home/user/domains/mydomain.com/public_html/wp-content/themes/twentyelevenmodified/header.php(68) : eval()'d code:1) in /home/user/domains/mydomain.com/public_html/wp-content/themes/twentyelevenmodified/header.php(68) : eval()'d code on line 1
The above is when I try mydomain.com
When I try mydomain.com/wp-admin/, I am redirected to wp-login.php and getting the following error:
Fatal error: Cannot redeclare _421736532() (previously declared in /home/user/domains/mydomain.com/public_html/wp-login.php(80) : eval()'d code:1) in /home/user/domains/mydomain.com/public_html/wp-login.php(80) : eval()'d code on line 1
Pulling my hair out trying different things since 5 hours now. Any help will be appreciated.
EDIT: After testing, I found that the function.php file is correctly calling function twentyeleven_header_style() and the problem is coming just after calling this function. So it's the next function call that is causing the problem. If I could know what is the next function !!!
Wordpress doesn't use functions with those names. Deactivate your plugins or rename the plugins folder.
If that doesn't work then it's probably coming from your theme. Rename your theme folder so wordpress will revert to the default (assuming the default theme exists).
It sounds like you purchased a theme or plugin with obfuscated code and it's using eval() to run it and probably making a call home.
After much research, I found that the site in question was hacked. More than 100 files were corrupted with codes. I cleaned them all and now things are functioning.
For others facing the same problem, download the whole files to your computer and look for eval codes (can be easily recognized).

Error Loading Zend Gdata framework into Wordpress

I am trying to use the Zend Gdata framework with wordpress but I am having some issues.
Now everything works perfectly fine when I test on localhost with XAMPP. However on my web server my code breaks down.
Here is my code to include the framework.
`set_include_path(TEMPLATEPATH . '/includes/');
require_once ('Zend/Loader.php');
Zend_Loader::loadClass('Zend_Gdata_Youtube');`
That code produces the following error.
Warning: Zend_Loader::include_once(Zend/Gdata/Youtube.php) [zend-loader.include-once]: failed to open stream: No such file or directory in /home/damain/public_html/mysite.com/wp-content/themes/mysite/includes/Zend/Loader.php on line 146
Warning: Zend_Loader::include_once() [function.include]: Failed opening 'Zend/Gdata/Youtube.php' for inclusion (include_path='/home/damain/public_html/mysite.com/wp-content/themes/mysite/includes/') in /home/damain/public_html/mysite.com/wp-content/themes/mysite/includes/Zend/Loader.php on line 146
Fatal error: Uncaught exception 'Zend_Exception' with message 'File "Zend/Gdata/Youtube.php" does not exist or class "Zend_Gdata_Youtube" was not found in the file' in /home/damain/public_html/mysite.com/wp-content/themes/mysite/includes/Zend/Loader.php:99 Stack trace: #0 /home/damain/public_html/mysite.com/wp-content/themes/mysite/includes/modules/yt_link_checker.php(19): Zend_Loader::loadClass('Zend_Gdata_Yout...') #1 /home/damain/public_html/mysite.com/wp-includes/plugin.php(405): load_zend_gdata('') #2 /home/damain/public_html/mysite.com/wp-admin/admin.php(111): do_action('load_zend_gdata', Array) #3 /home/damain/public_html/mysite.com/wp-admin/index.php(10): require_once('/home/damain/...') #4 {main} thrown in /home/damain/public_html/mysite.com/wp-content/themes/mysite/includes/Zend/Loader.php on line 99
I cannot seem to figure this issue out. Can anyone help?
The best solution in this case is to run the script requiring the Zend Loader and use var_dump(get_include_path()) to see what the server says the path is. Then keep modifying the php.ini include_path until the script finds it.
In your case, I'm not sure if 'damain' is supposed to be 'domain'. My include path which finally worked was:
/home2/thelove6/public_html/zf/ZendGdata/library" thelove6 being the username.
Did you look to see if those files exist in those directories? (/mysite/includes/Zend/Loader.php) and they have the correct permissions? It sounds like that could very well be the issue. The other thing to check with a simple phpinfo() would be that you have all of the libraries install on the live server.
Ok, the possible reason is: You're not using the proper case for the classname. For the version 1.11.11, it will be Zend_Gdata_YouTube rather than Zend_Gdata_Youtube.
Windows OS is ignoring the case, whereas the Linux server does not. Hope this will solve your problem, just look at the proper case of the Class or filenames.

Resources