I have IPB and I have an PHP application which is outside of forum ROOT and on another subdomain as well.
In application I need to have access to member data, eg. posts count, email etc.
I have the latest IPB version and PHP 5.6
I googled a lot for solution, and finally I found this one:
Accessing IPB Classes Externally From Main Website
However, it didn't worked at all. There is no errors, just redirection to main forum URL.
Does anybody have experience wit IPB classes and or it's API?
Can somebody help me to reach the goal.
Solution is probably just one line of code.
EDIT:
I found work around, check out my answer below.
However I'm still interested for "nicer" solution.
After some research, I configured out that IPB redirects because board url doesn't match with current URL/subdomain. (my case)
So... There is workaround, not so nice but works at least, and is one-line solution:
<?PHP
$_SERVER['HTTP_HOST_R'] = $_SERVER['HTTP_HOST']; // Keep original info in another index.
$_SERVER['HTTP_HOST'] = "www.your-ipb-forum.com"; // Work-around
$forumPath = '../forum'; //FORUM FOLDER
define( 'IPS_ENFORCE_ACCESS', TRUE ); // Important so it does not redirect to forums
define( 'IPB_THIS_SCRIPT', 'public' );
require_once( $forumPath.'/initdata.php' );
require_once( IPS_ROOT_PATH . 'sources/base/ipsRegistry.php' );
require_once( IPS_ROOT_PATH . 'sources/base/ipsController.php' );
$ipbRegistry = ipsRegistry::instance();
$ipbRegistry->init();
// Init done
$member = IPSMember::load($memberName, 'all', 'username');
print_r($member); // For demo purposes only
The third line is work-around with which we cheat on IPB.
The second line is "moving" $_SERVER['HTTP_HOST'] data to $_SERVER['HTTP_HOST_R'] so if you need current(real) URL in your application, you may use this variable instead because HTTP_HOST one is changed. (needed for workaround).
Related
I am facing a strange issue with WordPress. When I put this line as a code snippet in a blog post:
$app = require_once __DIR__.'/../bootstrap/app.php';
I get a 404 error when I try to preview the page, and I wont be able to save the post at all but if I make the line of code incorrect for example, remove the last 'e' from require, this way:
$app = requir_once __DIR__.'/../bootstrap/app.php';
everything works fine. Is the code somehow executing and causing problems?
Your web host probably has a paranoid web application firewall (most likely mod_security) enabled, with rules to block requests which contain data which looks like PHP code.
Contact your web host and request that they turn this feature off.
Wordpress is a little funny that way, try using get_stylesheet_directory() function. This will return the path to your theme directory.
require_once( get_stylesheet_directory() . '/path/to/bootstrap.css );
Also the require_once function doesn't return anything so there is no point trying to assign it to a variable.
Trying to teach myself a little about writing Wordpress plugins and things and I am running into problem I can't seem to figure out. I guess I'm not sure exactly what I need to change here. The code below returns the domain name "www.mydomain.com" for the plug in. I'm trying to get it to include the page name as well. I'm assuming that the "site_url()" is not the proper function to be using really, but can't figure out what would be used in place. Any help would be appreciated.
$site_url = wp_parse_url( site_url() );
define( 'HOSTNAME', $site_url['host'] );
Background: had a working Wordpress 3.7 site at olddomain.com.
I moved it to newdomain.com successfully, and in the process added this to wp-config:
define('WP_HOME','http://newdomain.com');
define('WP_SITEURL','http://newdomain.com');
Now when I attempt to login from newdomain.com/wp-admin I'm getting the cross-browser error (despite having cookies enabled and clearing existing cookies):
ERROR: Cookies are blocked or not supported by // your browser.
You must enable cookies to use WordPress.
I tried going into wp-login.php and commenting out the following lines (744-747) to stop the conditional testcookie check
// If cookies are disabled we can't log in even with a valid user+pass
if ( isset($_POST['testcookie']) && empty($_COOKIE[TEST_COOKIE]) )
$user = new WP_Error('test_cookie', __("<strong>ERROR</strong>: Cookies are blocked or not supported by // your browser. You must <a href='http://www.google.com/cookies.html'>enable cookies</a> to use WordPress."));
else
$user = wp_signon('', $secure_cookie);
but doing that leaves me stuck in a redirect loop back to the admin page:
http://myapp.com/wp-login.php?redirect_to=http%3A%2F%2Fmyapp.com%2Fwp-admin%2F&reauth=1
Do I need to change (or not set) the site URL? or is there another potential way to troubleshoot this? thanks
add to wp-config.php
define('ADMIN_COOKIE_PATH', '/');
define('COOKIE_DOMAIN', '');
define('COOKIEPATH', '');
define('SITECOOKIEPATH', '');
original source http://wordpress.org/support/topic/cookie-error-site-not-letting-me-log-in
Having migrated hundreds of WP sites, here's a few thoughts :
If migrating the DB : Check the database options table (probably wp_options) column "option_name" that values "siteurl" and "home" have the correct "option_value" for your site. "siteurl" is huge.
I can testify that the options table tweak is the bare minimum required to migrate a DB to a new domain in WP. (will not cause redirection, will still have issues)
WP looks up these DB options to serialize the site to domain and I am pretty sure the defines are lower in the stack and of no help. Consider the wp-admin activities as loosely coupled to the front. You can break everything (done it) in the front and the admin will still function.
Also - did/does the site work with generic install/no migration or tweaks?
As mentioned - .htaccess (missing or misconfigured) will cause your error. Regarding the .htaccess file, if used, this is a dot.file and many operating systems will "ignore" or "make invisible" so a copy/paste or FTP application or similar may not carry the .htaccess
(pretty sure on this) If you moved the DB and used pretty urls, and missed the .htaccess that could be all you need to fix. I just tested locally on a sandbox install and the table wp_option column "option_name" value "permalink_structure" when left blank in column option_value will return to ?p=1 (non-permalink) status and .htaccess will be mostly bypassed.
This worked for me.
Remove //define('COOKIE_DOMAIN', 'www.domain.com');in your wp-config.php
Ensure that all the files have the ANSI format and not utf-8
This error also occurs when moving a multisite installation to a new domain if you update all options on the database table (usually wp_options), but forget to change the DOMAIN_CURRENT_SITE line on wp-config.php:
define( 'DOMAIN_CURRENT_SITE', 'yourdomain.com' );
I experienced this due to my caching plugin.
W3 Total Cache had added the following to my wp-config.php file:
define('COOKIE_DOMAIN', 'www.olddomain.com'); // Added by W3 Total Cache
Since it was hard coded, it didn't update to the new site domain. After deleting the added code (because I don't currently use the plugin), I was able to log in again.
I'd check wp-config.php for the word "cookie" to see if a plugin might have added something like this.
I was getting this same error.
I had hard coded the Home and SiteURL in wp-config.php for a brand new website - no plugins even installed.
The problem: I had a space at the end of the URL.
define('WP_HOME','http://100.000.000.01/~acctname/wp ');
define('WP_SITEURL','http://100.000.000.01/~acctname/wp ');
Removing the space fixed this error.
define('WP_HOME','http://100.000.000.01/~acctname/wp');
define('WP_SITEURL','http://100.000.000.01/~acctname/wp');
this bug was driving me crazy the last couple of days so i thought after fixing it to share with you guys! the problem was when i was trying to login into my wordpress backend i got this annoying cookies error so this is how i fixed it!
Go to your ftp and your domain.
Afterwards go to your wp-contents
Go to your themes folder
Chose the theme that is active
Look for functions.php of your teem and open it
At the ende of the code you should see closing tag p> just remove it clear the spaces also and save it!
Go to your domain.com/wp-login.php
and try to login it should be fixed afterwards you can put the tag back where it was and save it again that was the solution for me this trick also fixes the white page problem in wordpress
Cheers!
I have been googled & tried all ways to get rid of this cookie issue. Finally i found two solutions, which could help you.
Solution 1:
yoursite/wp-login.php
Comment following lines 770-773
Code
if ( isset($_POST['testcookie']) && empty($_COOKIE[TEST_COOKIE]) )
$user = new WP_Error('test_cookie', __("<strong>ERROR</strong>: Cookies are blocked or not supported by your browser. You must <a href='http://www.google.com/cookies.html'>enable cookies</a> to use WordPress."));
else
$user = wp_signon('', $secure_cookie);
It might work for some websites and some sites may show blank page. Moreover, this is not recommended,as this file may be overridden after wordpress update so try for second solution.
Solution 2:
yoursite/wp-content/themes/yourthemeFolder/functions.php
Place following code.
setcookie(TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN);
if ( SITECOOKIEPATH != COOKIEPATH )
setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
Updating of your theme may also loose these changes so please place this code in another functions.php, which is under your child-theme folder in your current active theme. Hope, this will help you.
Assuming you are running on a Unix/Linux type platform - please ensure you have copied your .htaccess file from your original server and updated any references to the old domain within that file. It will be in the root of your wordpress deployment (if you are using it).
Either that or you may have a reference to your old domain somewhere in your wp_options table within the database.
Be forewarned that as you have moved from one domain to another, images and media locations within posts may need to be updated. You can either do that yourself directly within the database, use a find/replace utility or manually re-point your images within your posts. An alternative method to fix your post data is to export all your posts from your old site (from within the admin panel) - Tools > Export > All posts; then manually update the URL within that resultant file before importing to your new site.
All of this and much more is covered over at codex.wordpress.org. For more information see this link:
http://codex.wordpress.org/Changing_The_Site_URL
IMPORTANT NOTES:
If you are going to modify anything directly within the database, make sure you read the section that talks about GUIDs
If you are using Better WP Security, there are other things you may need to do, but based on what you are describing, I doubt you have it installed.
I had the same problem with very similar circumstances and spec.
Eventually after trying all sorts of different solutions suggested online, I just renamed my active theme via FTP and then was able to login to the dashboard, I renamed my theme back and everything worked, I've no idea why but it may help somebody fix issues they're having.
I had the same problem and nothing works. After upgrading my php 5.3.x to 5.4.x it works fine.
Following step solve my issue
on wp-config.php
//define('WP_CACHE', true); // Added by W3 Total Cache Block this line
//define("COOKIE_DOMAIN", "www.domain.com"); Block this line
Delete following files from wp-content
object-cache.php
advanced-cache.php
db.php
I created my Multisite install long ago when you needed a plugin for domain mapping. So I had the file '/wp-content/sunrise.php' and in the wp-config define( 'SUNRISE', 'on' ); It's been working just fine until a recent update to WordPress.
I viewed these errors in my debug.log:
Undefined index: HTTP_HOST in ../public_html/wp-content/sunrise.php on line 10
Undefined index: HTTP_HOST in ../public_html/wp-includes/ms-settings.php on line 57
So I deleted the sunrise file and wp-config sunrise definition and added #max4ever/#duck_boy's cookie definitions to the wp-config file:
define('ADMIN_COOKIE_PATH', '/');
define('COOKIE_DOMAIN', '');
define('COOKIEPATH', '');
define('SITECOOKIEPATH', '');
That solved the problem. I can now login!! Note: I tried this definition and it worked as well. Taken from Multisite Setup Guide
define( 'COOKIE_DOMAIN', $_SERVER[ 'HTTP_HOST' ] );
I came across this error when trying to install a wordpress site on localhost. The problem was this line inside the .htaccess
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
It prevents cookies being set if not on https. Just had to remove the line.
I have found very good solution of this issue
There are possible following solutions for this error
Coding Error
Unnecessary Spaces in Code
Caching & Security Plugin
Check this article: https://www.scratchcode.io/cookies-are-blocked-or-not-supported-by-your-browser/
My WordPress login page at mysite.com/wp-login.php is giving me a cannot connect to 127.0.0.1 error.
The site works, and other WordPress admin pages are available, like upgrade.php. I've done some googling, tried some of the suggestions here: http://wordpress.org/support/topic/error-establishing-a-database-connection-112
But to no avail. Admin has been working for weeks and nothing has been changed. Everything also looks correct in config.php. The site is on AN Hosting, and I logged into the phpMyAdmin on the cPanel and everything seems to be in order with the database
I have very little experience with database issues and MySQL, so I am a little flummoxed.
Same problem. AN Hosting is blocking you. They are blocking any attempt to login on some of their shared servers. I changed wp-login.php page to a new address, and corrected all references in the WordPress folder.
Now everything works fine. However, it will only work until the next update.
AN Hosting says they are doing this only temporarily because they've been facing some type of attack on WordPress logons. If you ask me this is very lame. They need to resolve this issue.
Call them! I will also call them again and complain.
Thats strange if it was working before, and not now.
I'm used to get trouble connecting to my database with WordPress (since I'm installing WordPress websites many oftern), but when ever it failed for me the problem were in the hostname
I would suggest you to check your database hostname, if you can log in to cPanel you can find out form the data base interface
Look here:
Then check this section for the hostname:
If you specified correctly there should be no problem
After seen the comment you left after your question, this came to my mind
Go into
PhpMyAdmin -> Your WP Database -> Options Table and check the site url value, it might be still pointing to your old dev url
So based on the answer given by #user3035755 , I can give you the following work-around:
In your root directory, create a file called(for instance - you can change that if you want to) login.php(not sure if the word "login" would be accepted - you might have to play around with it a bit, until something works). In this file add the following code:
<?php
include_once( dirname( __FILE__ ) . '/wp-login.php' );
This code will include the original wp-login.php file. I'm not sure how their restriction works - if it's based on where the call to the database is being made(as in from which exact file), then it might fail due to the fact that the connection would still be made from wp-login.php(although I assume that's not how they did it). If they instead check the file that is being executed, then you should be fine(since in that case it would be login.php - again, you might have to change that).
Now, that's just the first step - you can either manually go to login.php every time you want to log-in, but it'd be better if the login URL is automatically adjusted. To do that, go to the /wp-content/ directory and create(if it doesn't already exists) a mu-plugins1 directory. In there create a new file, called new-login.php and in that file put the following code:
<?php
/*
Plugin Name: New Login URL
Plugin Description: Makes the login URL /login.php instead of /wp-login.php
*/
function nl_login_url_filter( $login_url ) {
return str_ireplace( home_url( '/wp-login.php' ), home_url( '/login.php' ), $login_url );
}
add_filter( 'login_url', 'nl_login_url_filter', 10 );
function nl_logout_url( $logout_url ) {
return str_ireplace( home_url( '/wp-login.php' ), home_url( '/login.php' ), $logout_url );
}
add_filter( 'logout_url', 'nl_logout_url', 10 );
So what happens in this plugin, is that it simply hooks to the login_url and logout_url filters and changes http://mydomain.com/wp-login.php?test1=23&test4=56 to http://mydomain.com/login.php?test1=23&test4=56.
This way you don't have to take care of always entering login.php instead of wp-login.php.
Again - if that doesn't work, try using a different name for the file, like enter.php(for instance), just remember to change the file name in the new-login.php file as well.
Footnotes:
The /wp-content/mu-plugins/ directory is a special directory. All .php files directly inside it(not in a sub-directory) get included in alphabetical order. So basically any plugin you put in there will always be enabled(the only way to disable a mu-plugin is to delete it's file in the mu-plugins directory). You can read more about mu-plugins here
Been there done that, but that does not mean my guide-lines have the same positive result
for you but maybe it helps a little. Below a small roadmap with steps you could take:
These 2 (site url and home) you could add in wp_config.php.
define('WP_HOME','http://yoursite.com');// blog url
define('WP_SITEURL','http://yoursite.com'); // site url
Did it make any change for login? maybe you check the phpMyAdmin (through cPanel).
Check wp_options ( the $table_prefix = '???_' ??? is what you have put there,
you find it in wp-config.php).
Now look at line 1 option_id 1 / option_name siteurl / option_value here must be your domain url.
Now find around line 36 option_id 36 / option_name home / option_value here should be your domain url.
IF they where not correct I assume you made corrections, saved them into the db and check if you are able to login now.
Stil not working? maybe following would good to check also:
What the .htaccess file shows (correct path?)
Add if not already done some debug "stuff" in wp_config.php:
define( 'WP_DEBUG', true ); // Or false to disable
if ( WP_DEBUG ) {
define( 'WP_DEBUG_LOG', true ); // writes errors down in wp-content/debug.log
define( 'WP_DEBUG_DISPLAY', true ); // shows errors on screen output, set to false so only write into logfile
define('SAVEQUERIES', true); // will have a performance impact so disable if not needed
define('SCRIPT_DEBUG', true); // Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
}
If no debug.log is shown in wp-content you create the file by hand.
Btw, is the wp-login.php having the correct chmod? (644 it should be)
Do you have/use cache plugins if so, could try to disable it by renaming folder.
Do you have some caching options through .htaccess if so, disable it for the moment.
Do you use a login plugin or script? If so, disable it for the moment being.
You could check functions.php (in your theme folder) if there is some code-snippet which could do a redirect for your wp-login.php, if so disable it for the moment.
Last but not least, if all above still not was solving your problem you could rename the plugins folder for a moment and try to login. (don't forget tot rename it back afterwards)
I hope that one of these will help you to find the solution.
Ask your hosting provider what your database host should be and update the DB_HOST line in wp-config.php accordingly.
This is usually localhost or 127.0.0.1 but on some hosts it may be something completely different that you would not be able to guess without asking - for example I've had long weird hostnames supplied by GoDaddy for this before (years ago when I still used GD for anything).
I have a directory inside my wordpress directory for some template application
apacheWWW/wordpress/jtpc
In my application i want the wordpress current user id
I am able to do this in one page but in the other I get an error
This is what I am doing to get the user id:
require_once( '/../../wp-load.php' );
global $current_user;
get_currentuserinfo();
$user_id = $current_user->ID;
but I get an error on this line
require_once( '/../../wp-load.php' );
The error says
File does not exist: D:/programming/apacheWWW/wordpress/jtpc/ajaxHandlers/wp-admin, referrer: http://localhost/wordpress/?page_id=23
what dose he wants with the wp-admin ,
and why he is looking for it in the wrong directory ,
It's suppose to be under
D:/programming/apacheWWW/wordpress/
It's working for one page, (I am uploading file and creating a directory for this user id)
but for the other page I send an ajax request to delete files by user request
so I need to id again, but there he throws the error
ok got i working i put
require_once( '/../../wp-load.php' );
at the top of the page
and not inside the function
My issue is that I've set up a standalone ajax controller for my plugin's admin.
In hindsight, I wish I didn't, because now I need $current_user->ID on a particular method.
using the following code gives me undefined function errors:
global $current_user;
get_currentuserinfo();
same when I use this:
$current_user = wp_get_current_user();
I've used GREP to trace the spaghetti function calls, and was able to get stable using the following chain of includes within my ajax_request method of my base controller:
include APP_ROOT.'wp-includes'.DS.'meta.php';
include APP_ROOT.'wp-includes'.DS.'plugin.php';
include APP_ROOT.'wp-includes'.DS.'user.php';
include APP_ROOT.'wp-includes'.DS.'capabilities.php';
include APP_ROOT.'wp-includes'.DS.'load.php';
include APP_ROOT.'wp-includes'.DS.'functions.php';
include APP_ROOT.'wp-includes'.DS.'pluggable.php';
(I have defined my own APP_ROOT, which is the include path to the base of the whole application.)
This eliminates my errors, but I am still getting a user id of 0, and data is NULL, which doesn't solve my problem.
Surely there is a better way to do this. Has anyone deciphered the cookie or session variables for direct access?
Any and all suggestions would be welcome. I know I'm asking a lot for wordpress to work like normal OOP/MVC code...
In addition, I have deployed a CodeIgniter front-end, and I am using WordPress solely for the back-end. I highly recommend this for ultimate flexibility if you are forced to use WordPress. Front-end hooks are a pain, and really kind of "hacky". Here's where I got the idea:
http://jidd.jimisaacs.com/post/wordigniter-wordpress-codeigniter/
So if anyone has any questions about that, I bet I could help.
Best regards, happy coding.
You may want to try one of the following two lines:
require_once STYLESHEETPATH . '/wp-load.php';
or
require_once TEMPLATEPATH . '/wp-load.php';
There is a slight difference between the STYLESHEETPATH constant and the TEMPLATEPATH constant. If you are developing a child theme, STYLESHEETPATH will be the child theme path, while TEMPLATEPATH will be the parent theme path.
This is how you can get current user:
global $current_user;
$current_user = wp_get_current_user();
After that, you can use $current_user->ID where you want.
More Info:
Function Reference/wp get current user