Forum Moderators: coopster

Message Too Old, No Replies

Error Redirection

what's the best way to do this:

         

loiosh

11:49 pm on Aug 10, 2005 (gmt 0)

10+ Year Member



heya guys.
this, to me, seems pretty straight forward.

the thought:

rather than
err='';
if (something not good) { $err=foo;}
if ($err!== '') {make page here including $err}

do:
if (something bad) {$_SESSION['errmsg']=foo; header 'location:error.php'}

error.php:

<?php include "includes/prehtml.php";
if(isset($_SESSION['errtitle'])){$title=$_SESSION['errtitle'];}
else{ $title="You Must Be Logged in to Access";}
include "includes/pagetop.php";
include "includes/header.php";?>
<body>
<?php include "includes/layoutbars.php";
if (isset($_SESSION['errmsg'])) {$errmsg=$_SESSION['errmsg'];}
else {$errmsg="It appears you have attempted to access parts of the site that require you to be logged in.
<br>You must register if you do not already have an account.<br>";

$userid= $_SESSION['userid'];
}?>
<div id="main">
<h1>Welcome</h1>
<?echo $errmsg;?></div><?php include "includes/footer.php";?>

Pertinent code calling error.php:

if (mysql_num_rows($verResult) ==0) {$errormsg="bad monkey.<br>not permitted.<br>";}//trimmed for brevity

if ($errormsg!==''){
$errtitle="ERROR - View Coin History";
$_SESSION['errtitle']= $errtitle; $_SESSION['errmsg'] = $errmsg;
header('Location: error.php');
}else {

unexpected result:
Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

loiosh

12:52 am on Aug 11, 2005 (gmt 0)

10+ Year Member



erm... nevermind. just took walking away from it for 5 minutes to see my mistake.

jatar_k

1:47 am on Aug 11, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld loiosh,

that happens with me too, sometimes just posting something I can see it differently.

glad you got it sorted

FiRe

2:38 pm on Aug 11, 2005 (gmt 0)

10+ Year Member



you dont have to use sessions if you include the error page!

if ($error) {
$error_msg = "Missing field!";
include ("error.php");
exit();
}

then in error.php just echo $error_msg