0

I've tried to look into why this isn't echoing but every result the persons trying use php on an html page so this is why I'm here asking.

I have 3 php files, a login file, a global config file, and a theme file. The login page echo's the login script but it connects to the global file. The global file connects to the theme file and the db config file. The theme file is a simple table.

Here's my files

<?
include('../tools/global.php');



switch($_POST[act]){

case "setlogin":
set($login);
break;

case "refresh":
refresh();
break;

case "logout":
lout();
break;

default:
login($mes);
break;
}

function login($mes){


if (isset($_COOKIE["user"])){
$out[body]="<br />
<center>
<table width='90%' border='0' cellspacing='1' cellpadding='1' bgcolor='#BDBDBD'>
<tr bgcolor='##ff80ff'>
<td width='100%' valign='center' align='left' colspan='2' background='#BDBDBD'>
<strong>Login</strong>
</td>
</tr>
<tr bgcolor='#BDBDBD'>
<td width='100%' valign='center' align='left'><center>
<b>You are already logged in! Would you like to <a href='http://www.fivedesignguys.com/dir/panel/login.php?act=refresh&type=logout'>Logout?</a></center></td></tr>
</table>
</center><br /><br /><br /><br />";

}else{

$out[body]="
<br />
<center>
<table width='400' border='0' cellspacing='1' bgcolor='#BDBDBD' cellpadding='1'>
<form method='post'>
<tr bgcolor='$config[altcolor]'>
<td background='#BDBDBD' width='100%' valign='center' align='left' colspan='2'>
<strong>Login</strong>";

It continues but I know it's going to echo me the first option,

Heres the global php file

<?php

include('../theme/default.php');
include('config.php');

?>

and finally the default.php theme file

<table border='0'>
<tr>
<td colspan='2'>
<center>bar</center>
</td>
</tr>
<tr>
<td width='10%'>
hey<br>hey<br>
</td>
<td>
hello
<?php

echo $out[body];
?>

</td>
</tr>
</table>

as you can tell I want it to echo $out[body] but it doesn't want to. Yes all the files are PHP but this is where I'm stuck.

2
  • 2
    First of all it has to be $out["body"] and then it is not a global variable. Its a variable defined inside your function and hence you cannot echo it outside just like that. Either return the variable to main control or make it global Commented Nov 13, 2013 at 3:54
  • Array should be like $out['body'] instead of $out[body] Commented Nov 13, 2013 at 4:00

1 Answer 1

1

The $out array is not a global, so it can't be read outside the login() function.

You should declare the array as global and read a bit about globals.

Sign up to request clarification or add additional context in comments.

1 Comment

I changed the variable to $body so setting global $body; didn't work. Would I have to wrap it in a function and then would it be able to be accessed for example a register.php page?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.