Jump to content

[solved] $session broke my site


psy
 Share

Recommended Posts

I've been working on a a new site for weeks. $session did it's normal, wonderful stuff until today when it didn't - boom!!!

$session now occasionally holds vars from one page to another. The killer is $session->location or $session->redirect. Before redirecting, the page crashes with:
image.thumb.png.c979bc1015e2cfec5d2826920284b076.png

I went back to basics with the default theme:

Spoiler

<?php namespace ProcessWire;

// home.php (homepage) template file. 

$session->set('hello', "hello from page 1");

// Primary content is the page body copy
$content = $page->body;

// Append navigation to child pages underneath the body copy
// See the _func.php file for the renderNav() function example
$content .= renderNav($page->children); 

// if there are images, lets choose one to output in the sidebar
if(count($page->images)) {
    
    // if the page has images on it, grab one of them randomly... 
    $image = $page->images->getRandom();
    
    // resize it to 400 pixels wide
    $image = $image->width(400); 
    
    // output the image at the top of the sidebar
    $sidebar = "<img src='$image->url' alt='$image->description' />";
    
    // if image has a description, display it underneath
    if($image->description) $sidebar .= "<blockquote>$image->description</blockquote>";
    
    // append sidebar text content if page has it
    $sidebar .= $page->sidebar; 
    
} else {
    // no images... 
    // make sidebar contain text content if page has it
    $sidebar = $page->sidebar; 
}

// basic-page template:

<?php namespace ProcessWire;

// basic-page.php template file 

print_r($_SESSION);
print_r($session->getAll());
print_r($session->hello);
$session->location($pages->get(1)->url);

// Primary content is the page's body copy
$content = $page->body; 

// If the page has children, then render navigation to them under the body.
// See the _func.php for the renderNav example function.
if($page->hasChildren) {
    $content .= renderNav($page->children);
}

// if the rootParent (section) page has more than 1 child, then render 
// section navigation in the sidebar (see _func.php for renderNavTree).
if($page->rootParent->hasChildren > 1) {
    $sidebar = renderNavTree($page->rootParent, 3); 
    // make any sidebar text appear after navigation
    $sidebar .= $page->sidebar; 
}

// in default install basic-page template
// on frontend, clicking menu link from home page to about page

// print_r($_SESSION);
Array ( [Session] => Array ( [hello] => hello from page 1 ) )

// print_r($session->getAll());
Array ( [hello] => hello from page 1 ) 
 

// print_r($session->hello); 
hello from page 1

// $session->location($pages->get(1)->url);
Fatal error: Exception: Method WireHttp::sendStatusHeader does not exist or is not callable in this context (in /home/path/to/my/site.com/wire/core/Wire.php line 563) #0 /home/path/to/my/site.com/wire/core/Wire.php(419): ProcessWire\Wire->___callUnknown('sendStatusHeade...', Array) #1 /home/path/to/my/site.com/wire/core/WireHooks.php(952): ProcessWire\Wire->_callMethod('___callUnknown', Array) #2 /home/path/to/my/site.com/wire/core/Wire.php(484): ProcessWire\WireHooks->runHooks(Object(ProcessWire\WireHttp), 'callUnknown', Array) #3 /home/path/to/my/site.com/wire/core/Wire.php(487): ProcessWire\Wire->__call('callUnknown', Array) #4 /home/path/to/my/site.com/wire/core/Session.php(1401): ProcessWire\Wire->__call('sendStatusHeade...', Array) #5 /home/path/to/my/site.com/wire/core/Wire.php(419): ProcessWire\Session->___redirect('/', 302) #6 /home/path/to/my/site.cli in /home/path/to/my/site.com/index.php on line 64
Fatal error: Uncaught ProcessWire\WireException: Method WireHttp::sendStatusHeader does not exist or is not callable in this context in /home/path/to/my/site.com/wire/core/Wire.php:563 Stack trace: #0 /home/path/to/my/site.com/wire/core/Wire.php(419): ProcessWire\Wire->___callUnknown('sendStatusHeade...', Array) #1 /home/path/to/my/site.com/wire/core/WireHooks.php(952): ProcessWire\Wire->_callMethod('___callUnknown', Array) #2 /home/path/to/my/site.com/wire/core/Wire.php(484): ProcessWire\WireHooks->runHooks(Object(ProcessWire\WireHttp), 'callUnknown', Array) #3 /home/path/to/my/site.com/wire/core/Wire.php(487): ProcessWire\Wire->__call('callUnknown', Array) #4 /home/path/to/my/site.com/wire/core/WireShutdown.php(405): ProcessWire\Wire->__call('sendStatusHeade...', Array) #5 /home/path/to/my/site.com/wire/core/WireShutdown.php(581): ProcessWire\WireShutdown->sendFatalHea in /home/path/to/my/site.com/wire/core/Wire.php on line 563

Using ProcessWire 3.0.212 dev

PHP v8.1 (tried 7.4 & 8.0 too)

Error occurs in Chrome & Firefox

Editing modules, eg turning TracyDebugger on/off also triggers the problem

Error occurs in front and back end. Often, clicking on a link to a different page clears the error but $session still screwy.

Have no idea why PW suddenly stopped correctly wiring $session.

Is this a bug? Am I doing something wrong?

Help & ideas on how to fix gratefully accepted.

 

Solved:

Upload a fresh copy of WireHTTP to my server. Previous version may have been corrupted in transit.

Edited by psy
Problem solved
Link to comment
Share on other sites

Hi @psy

  1. Have you got anything on the site that hooks into session methods?
  2. Have you had a search for any similar open or closed issues on the processwire-issues repo? There might be something there that could help.
  3. You could try turning off unknown message method exceptions via the little-known "disableUnknownMethodException" config variable - this might get you through the line doing the redirect, but it will totally obscure the real issue here.

Hopefully others might have better suggestions, or @ryan might take a look.

Link to comment
Share on other sites

@netcarver

Thanks for your input.

  1. Site doesn't use any hooks
  2. Searched Google, forum but not repo. Will do so now. There was an old post that was vaguely similar but didn't have an answer. See link below
  3. Turning off the error may hide the error message but, you're right, it will totally obscute the real issue.

 

Link to comment
Share on other sites

I suppose the next thing I would try is editing the last part of the session::___redirect() function so it uses PHP to send the needed headers, taking WireHttp() out of the equation. Something like...

header("Location: $url");
exit(0);

 

Link to comment
Share on other sites

OMG solved🤞

When I was digging into wire/core/WireHTTP I think the file got corrupted, maybe during an upload to my dev server (yes, still staging)

Replaced it with a new copy and site is working again

@netcarver truly appreciate your help and patience.

  • Like 2
Link to comment
Share on other sites

  • psy changed the title to [solved] $session broke my site

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...