I'm trying to write some code to access the WordPress database.
Everything tells me to load wp-load.php to do this.
However I just get critical errors when I do.
This used to work a couple of months back, not sure when it stopped working, so might be a recent WordPress update that has stopped this working. Currently on WordPress 6.1.1
<?php
ini_set( 'display_errors', '1' );
ini_set( 'display_startup_errors', '1' );
error_reporting( E_ALL );
global $_SERVER;
$_SERVER['HTTP_HOST'] = 'www.mydomain.com';
$_SERVER['REQUEST_URI'] = '/';
$file_require = $_SERVER["DOCUMENT_ROOT"] . '/wp-load.php';
include $file_require;
if (file_exists( $file_require )) {
echo 'FILE EXISTS: file_require: ' . $file_require . '<br>';
} else {
echo 'FILE NOT FOUND: file_require: ' . $file_require . '<br>';
}
echo 'Successfully Loaded wp-load.php<br>';
The code after the include nevers gets executed.
Just get a "There has been a critical error on this website."
The site is a MULTISITE and some articles and similar questions do suggest that this may be teh cuase. But this used to work just fine and this has always been a multisite. As I say, this has stopped working during the last few weeks.
Any help would be gratefully received.
Related
i'm about to update my website and since i have offshored some code it want work anymore...
My problem now is, that i want to update the stats, when a new user visits my site but it doesn't go into the if, because the $_SESSION['exist'] is just true, even if not stated.
My code looks like this:
<?php
session_start();
if(!isset($_SESSION['exist'])){ //it doesn't go in this if
$_SESSION['exist'] = true;
$today = date("Y/m/d");
require(__DIR__ . '/./functions/select/stats/daily_view.php');
$dailyview = selectDailyView();
echo $dailyview['date'];
if($dailyview['date'] != $today){
//start COPY
$dv = selectDailyView();
require_once(__DIR__ . '/./functions/insert/stats/dailyview.php');
insertDailyView($dv[0]['date'], $dv[0]['dailyview']);
//end COPY
require_once(__DIR__ . '/./functions/update/stats/reset_daily_view.php');
updateResetDailyviewDate($today);
}
require_once(__DIR__ . '/./functions/update/stats/stats.php');
updateStat('index');
require_once(__DIR__ . '/./functions/update/stats/dailyview.php');
updateDailyView();
}
?>
So i tried to comment out everything except the session_start(); and to see whats stored in the $_SESSION i wrote a var_dump($_SESSION); and it says
array(1){["exist"]=>bool(true)}
I tried to clear the cache, unset the $_SESSION, destroy the session... Nothing worked. With unset($_SESSION); the output is NULL, but when i delete that line and reload the page the output still says
array(1){["exist"]=>bool(true)}
Do you have any idea?
You have to unset it :
unset($_SESSION['exist']);
So i have this webshop running on a server, it's working fine on every pc i have been able to get my hands on. but for some reason quite often customers still have problems with one header(location ) to a payment site. I checked everything codewise and tried a hundred different ways of breaking the payment link but haven't found one.
I'm assuming it's the header(location: ...) or the fact that it's three in a row (some php only verification pages inbetween) which might give some version trouble but i'm only guessing.
snip out of the index.php
ob_start();
require_once($Content_Path);
$zpfw_page_output = ob_get_contents();
ob_end_clean();
//************************************************
// Include the requested header / footer / etc..
//************************************************
//Here we include the HEADER HTML.
require_once($Config['AbsolutePath'] . '_headers/' . $Config['HeaderFilename']);
//Here we include the PHP PAGE.
echo $zpfw_page_output;
//Here we include the FOOTER HTML.
require_once($Config['AbsolutePath'] . '_footers/' . $Config['FooterFilename']);
The Content page is the only thing that changes ($Content_Path) So the customers puts hit products that he wants to buy in his basket and goes towards checkout, now every post done on our pages go to a posttogethandler to make it seo friendly (the indexpages uses the first 2 parameters (www.google.nl/module/page/test)
to change the content path everything behind that are used as parameters $_Get[Param1] = 'test'
posttogethandler.php:
<?php
if(isset($_POST))
{
include '../../../_bootstrap.php';
if(!empty($_POST['m']) && !empty($_POST['c']))
{
$post_string = '';
foreach($_POST as $key => $postitem)
{
if($key == 'm')
{
}
elseif($key== 'c')
{
}
else
{
$post_string = $post_string.$postitem.'/';
}
}
header('location:'.$Config['AbsoluteURL'].$_POST['m'].'/'.$_POST['c'].'/'.$post_string);
}
}
and for the actual check which creates a mollie payment and sends to person to the payment (again i will shorten it a bit to only containt the code it passes through if nothing is wrong) (No echo commands exist in this file)
<?php
$mollie = new Mollie_API_Client();
$mollie->setApiKey($Config['Mollie']['Api_Key']);
if(!empty($_GET['param1']) && $_GET['param1'] == 'checkout' && !empty($_SESSION['Customer_ID']))
{
/* alot of checks and inserts into mysql database to keep track */
if(!empty($_GET['param3']) && $_GET['param3'] == 'secretcode')
{
//for skipping payment
header('Location: ' . $Config['AbsoluteURL'] . 'account/order/' . $uniqueID);
exit;
}
else
{
$payment = $mollie->payments->create(array(
"amount" => mollieCartPriceIncTaxes($_SESSION['cart'],$_SESSION['Customer_ID'])[0],
"description" => "Payment for ...",
"redirectUrl" => $Config['AbsoluteURL']."account/order/payment/".$uniqueID."",
"webhookUrl" => $Config['AbsoluteURL']."cart/checkout/webhook"
));
$payment = $mollie->payments->get($payment->id);
zp_mysqli_query("Update orders set Order_MollieID = '".$mysqli->real_escape_string($payment->id)."' where Order_ID = '".$mysqli->real_escape_string($uniqueID)."'");
if(!empty($_SESSION['pick_up']))
{
unset($_SESSION['pick_up']);
}
header("Location: " . $payment->getPaymentUrl()."/#");
exit;
}
}
I'll edit it some more in a few hours, need to go now. this is hosted on a server so i've checked for html code being send first but can't find any nor experience any problems with it on any pc i've tried to open the website with.
any pointers would be much appreciated!
EDIT:
It seems to be a problem with redirecting to a page outside of the domain. I'm remaking the page so the button is a direct link to the payment page. This seems to work.
I have function within my login script that is causing me some problems. I believe this is the issue.
function load( $page = 'login.php')
{
$url = 'http://' . $SERVER['HTTP_HOST'] .
dirname( $_SERVER ['PHP_SELF'] );
$url = rtrim( $url , '/\\' );
$url = '/' . $page ;
header ( "location: $url" );
exit();
}
My users are in the db and can register fine - when using my login form I have a login form a script to check they have entered the info and also another one to validate the users. The problem being that when I/They attempt to login the action script or the logic dosnt move on it sits on that blank page...
Thats the white page of death :) There is an error, but it doesnt get shown. You can try adding this to the top:
error_reporting(E_ALL|E_STRICT);
That should give you the error on line 5 in this code, the $SERVER needs to be $_SERVER
To improve your code, this is valid too:
header('Location: /');
Relative url's. That piece of code will go to home, you can just to to your $page directly:
header('Location: /'.$page);
function load($page = "login.php") {
header(sprintf("Location: http://%s/%s/%s", $_SERVER["HTTP_HOST"], trim(dirname($_SERVER["PHP_SELF"]), "/"), $page));
exit();
}
I played around with this and I'm having trouble getting it to work. I've added it at the bottom of the functions.php file in my themes folder.. no dice.. It should be redirecting to mySecretString=foobar... When i go to wp-admin it just takes me to the admin page to login.. that page should be accessible anymore, it should only be accessible by whatever the variable $QS equals.
// Simple Query String Login page protection
function example_simple_query_string_protection_for_login_page() {
$QS = '?mySecretString=foobar';
$theRequest = 'http://' . $_SERVER['SERVER_NAME'] . '/' . 'wp-login.php' . '?'. $_SERVER['QUERY_STRING'];
// these are for testing
// echo $theRequest . '<br>';
// echo site_url('/wp-login.php').$QS.'<br>';
if ( site_url('/wp-login.php').$QS == $theRequest ) {
echo 'Query string matches';
} else {
header( 'Location: http://' . $_SERVER['SERVER_NAME'] . '/' );
}
}
add_action('login_head', 'example_simple_query_string_protection_for_login_page');
Can anyone help me get this working, it seems like it should be so easy but nothing is working for me.
Thanks in advance.
I'm not understood your requirements fully where you want to exactly redirect, it would always helpful to you when you use .htaccess files in root folder, where you can do necessary redirection instead of writing functions.
Redirect 302 /about http://www.example.net/our-company-info/
http://www.woothemes.com/2013/11/htaccess-url-redirects/
I have added some server side validation to a dropdown box on one of my pages and when I did the page wouldn't work anymore. The code I added is as follows:
$show_form = true;
if (isset($_POST['submit'])) {
//All of the server side validations
$validator = new FormValidator();
$validator->addValidation("hospital_name","dontselect=000","No facility was chosen");
if ($validator->ValidateForm()) {
// All the variables from the submission form
$userid = $_SESSION['user_id'];
$hosp = $_POST['hospital_name'];
header('Location: ../site_hospital' . $hosp . '/hospital_submitform.php?usr=' . $userid . '&&hosp=' . $hosp);
exit;
$show_form = false;
} else {
echo "<B style='color:red;'>The following errors occurred:</B>";
$error_hash = $validator->GetErrors();
foreach ($error_hash as $inpname => $inp_err) {
echo "<p style='color:red;'>$inp_err</p>\n";
}
}}
if (true == $show_form) {
Through pure chance I added ob_start(); as part of my debugging to the beginning of the page and suddenly my code worked properly but I have no idea why and I was hoping the community could throw out an educated guess as to why. When the code stopped working it would not execute my header command above, the page would simply refresh and not change location, when I added ob_start(); to the top of the page the page redirected as planned. So the overall question is why would the page not direct using the header command without ob_start? I'm sure alot more detail and code is necessary for a definitive answer but I'm hoping someone has run into this before or has an educated guess that may lead me to my own answers. Thanks for any insight.
it's because you were writing to the output stream and preventing the header from working properly. once you started buffering other outputs, you removed the obstacle to the header's operation.