0

My latest idea which didn't seem to work was to store the array in a session,

include_once "scripts.php"
.........
//some code later
                        $errorlog .= "a random message<br/>";
                        $_SESSION['errorlog']=$errorlog;
                        reloadPage();

And then if 'errorlog' wasn't empty then display it,

[code]
    <div class="randomclass">
        <?php
        displayErrors('errorlog');
         ?>
    </div>

//here are the functions
function reloadPage(){
    Header('Location: '.$_SERVER['PHP_SELF']);
}
function displayErrors($valuename = "errorlog"){
    if(!empty($_SESSION['valuename'])){
        echo $_SESSION['$valuename'];
        unset($_SESSION['$valuename']);
        return true;

        }else{
        return false;
        }
}
[/code]

scripts.php

<?php
    if(!isset($_SESSION)) session_start();
........

I have included scripts.php which starts with if(!isset($_SESSION)) session_start();.

I'm new to php, still making my first webpage (or actually, preparing scripts for it). I can't seem to successfully find bugs in my scripts because I don't know how to show the errors after a page reload is needed.

What I want, is a way to store strings like in this $errorlog and display it just like an echo(in div or whatever) after the page was reloaded

I don't get any errors with headers, the page reloads correctly but the problem is that no text is displayed after the page reloads, so I don't see why I shouldn't be using them unless you know another way to reload the page after script is done

  • 2
    You cannot call `header()` after any output, even a space, also, I always use `error_reporting(E_ALL); ini_set('display_errors', 1);` at the top of my script for debug purposes. I can't see `session_start()` on your script. – Pedro Lobito Apr 24 '14 at 17:39
  • This'll help: http://stackoverflow.com/q/8028957/1492578 – John Bupit Apr 24 '14 at 17:46

1 Answers1

0

surely this way is not the best one, but I think that the problem is very easy..

function displayErrors($valuename = "errorlog"){
    if(!empty($_SESSION['valuename'])){     // here you must put a variable $valuename instead a simple string 'valuename'
        echo $_SESSION['$valuename'];
        unset($_SESSION['$valuename']);
        return true;

        }else{
        return false;
        }
}

You must change the session key at this row whit: $_SESSION[$valuename]

if(!empty($_SESSION['valuename'])){

The correct function is the follow:

function displayErrors($valuename = "errorlog"){
    if(!empty($_SESSION[$valuename])){
        echo $_SESSION[$valuename];
        unset($_SESSION[$valuename]);
        return true;

    }else{
        return false;
        }
}

Bye! Marco