...

View Full Version : Variable/Array not taking in another folder



Taylor_1978
06-02-2007, 03:36 PM
Hey all... Been a while since I've been here! G'day to all!

Okay - so my issue is:



<?
session_start();

// index.php

include('includes/actions.php');

/*
Some HTML here!!!!
*/
echo $SET['content'];
?>




<?
// includes/actions.php

switch($_GET['action']){
case "register":
// module
$SET['module'] = "register.php";
// title
$SET['title'] = "Register New Account";
break;
default:
// module
$SET['module'] = "main.php";
// title
$SET['title'] = "Home";
break;
} // switch

include($URL.'/actions/'.$SET['module']);
?>


For this example I'll use "register" as the $_GET['action']:



<?

// actions/register.php

$SET['content'] = "All my content here (just to keep it short!)";

?>


My problem being that it is not showing up via the index.php page. If I put on register.php "echo $SET['content'];" it works fine - but I can't do this as my $SET['content'] should actually appear under the html not above it.

Any ideas why it would not be reading the value of the variable?

Thanks in advance! :thumbsup:

Fumigator
06-02-2007, 04:45 PM
An issue of scope, perhaps?

CFMaBiSmAd
06-02-2007, 07:00 PM
it is not showing up via the index.php page. If I put on register.phpIf the code you posted is for two or more separate pages (it is not clear from your post what or where each piece of code is located) $SET['anything'] won't persist between pages. All general purpose variables are destroyed when code execution ends on any page.

You have a session_start() statement, are you trying to use session variables to pass information between pages? If so, you need to use the $_SESSION[] array instead.

Taylor_1978
06-03-2007, 02:04 PM
An issue of scope, perhaps?

Sorry - that made no sense to me! lol.. Scope?


If the code you posted is for two or more separate pages (it is not clear from your post what or where each piece of code is located) $SET['anything'] won't persist between pages. All general purpose variables are destroyed when code execution ends on any page.

You have a session_start() statement, are you trying to use session variables to pass information between pages? If so, you need to use the $_SESSION[] array instead.

At the top of each code it states which page the code is in:

// index.php
// includes/actions.php
AND
// actions/register.php

And no, not trying to use session variables to pass the information.

The index page includes "includes/actions.php" and this page includes "actions/register.php"

In many situations before I have passed a variable from one page to another when "include()"d.. So not sure why it wouldn't work now.

Any help appreciated! :thumbsup:

whizard
06-03-2007, 02:08 PM
Sorry - that made no sense to me! lol.. Scope?

http://php.net/variables.scope

HTH
Dan

Taylor_1978
06-03-2007, 02:13 PM
Thanks! But on quick glance of this, it is referring to variables set in functions, however no functions are being used as yet. Or am I missing something?

CFMaBiSmAd
06-03-2007, 02:33 PM
One ore more of your include()'s are probably failing (I don't see where $URL is being set). Either check your web server log for errors and/or put the following two lines in after your first opening <?php tag -

ini_set ("display_errors", "1");
error_reporting(E_ALL);Changing your include() statement into require() statements will keep your code from blindly executing if the require() fails.

Taylor_1978
06-03-2007, 02:58 PM
Ok - did all that and this is what I'm getting:

Notice: Undefined variable: content in /home/goto/public_html/index.php on line 274

Line 274 is <?=$SET['content'];?>

Taking in what you said about maybe one of the includes isn't working, at the top of actions/register.php I added:

echo "hi";

The "hi" displayed at the top of the index page, which obviously indicates that it is including the page.

I tried changing all my includes to require, however this also did not work.

Oh and $URL is set in the includes/config.php page which is actually listed in the index.php, include('includes/congig.php'); but I left that part out in my example.

rafiki
06-03-2007, 03:03 PM
$SET['content'] is not set :)

Taylor_1978
06-03-2007, 03:09 PM
But it is set lol... Well, I'm pretty sure it is hehe. In register.php I have:

$SET['content'] = "html code";

Just to make things nice and simple, I even changed all the HTML code (incase some form of error was occurring, to $SET['content'] = "hi"; - And still the same error :(

CFMaBiSmAd
06-03-2007, 03:11 PM
Either the assignment statement $SET['content'] = ... in register.php is not being executed (contained in conditional logic or a return() statement is being executed before it is reached) or at some point after the assignment statement it is being unset(), since it does not exist at the point it is being echoed.

Taylor_1978
06-03-2007, 03:16 PM
Wouldn't I have to do an unset() in order for that to happen. And there is definitely no return() statement.

I think I understand what you are suggesting, so what I did was change $SET['content'] to $body in both register.php and index.php where I echo the variable.

Still, it does not show :(

CFMaBiSmAd
06-03-2007, 03:42 PM
You would need to post all the code in register.php and your main file to get more specific help with why it is not setting or keeping the value in the variable.

Since it is echoing your "hi" statement at the start of the include file, something is either happening with the code execution path or with the setting or unset()ing of the variable. If you assign a NULL or "" to the variable the variable will still exist and you would not be getting the "undefined" error message.

It is also possible that if you are setting this inside of a function that it won't exist outside the function (which is what Fumigator posted.)

Short answer - we only see what you post here. If you cannot find the cause, you will need to post your actual code.

Taylor_1978
06-03-2007, 04:11 PM
index.php



<?
session_start();
ini_set ("display_errors", "1");
error_reporting(E_ALL);
require('includes/config.php');
require('includes/menu.php');
require('includes/actions.php');


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>GOTO-League.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">

/* General layout */
a:link {
font-weight: normal;
text-decoration: none;
color: #005177;
}
a:visited {
text-decoration: none;
color: #005177;
font-weight: normal;
}
a:hover {
font-weight: normal;
text-decoration: underline overline;
color: #003300;
}
body {
background: #ffffe1;
color: #003300;
scrollbar-face-color: #006752;
scrollbar-arrow-color: #ffffe1;
scrollbar-track-color: #ffffe1;
scrollbar-shadow-color:#000033;
scrollbar-highlight-color:#66cc99;
scrollbar-3dlight-color:#ffffff;
scrollbar-darkshadow-Color:#003300;
font-family: Arial, sans-serif; font-size:12px;
margin-top: 0; margin-left: 0; margin-right: 0;
padding-top: 0; padding-left: 0; padding-right: 0;
}
text {
font-family: Arial, sans-serif;
font-size: 80%;
}
td {
font-family: Arial, sans-serif;
color: #003300;
font-size: 80%;
}
input {
background-color: #ffffe1;
font-family: Arial, sans-serif;
font-size: 9pt;
color: #003300;
}
textarea {
color: #003300;
background-color: #ffffe1;
font-family: Arial, sans-serif;
font-size: 9pt;
}
select {
background-color: #ffffe1;
font-family: Arial, sans-serif;
font-size: 7pt;
color: #003300;
}
.copyright {
font-family: Arial, sans-serif;
font-size: 10px;
}
.bold {
font-weight: bold;
}
hr {
color: #006752;
}

/* YaBB navigation links */
.nav {
font-size: 90%;
text-decoration: none;
color: #003300;
}
.nav:link {
font-size: 90%;
text-decoration: none;
color: #0000ff;
}
.nav:visited {
font-size: 90%;
text-decoration: none;
color: #005177;
}
.nav:hover {
font-size: 90%;
color: #0000ff;
text-decoration: underline overline;
}

/* YaBB alternating bgcolors */
.windowbg {
background-color: #cce6cc;
font-size: 11px;
font-family: Arial, sans-serif;
color: #003300;
}
.windowbg2 {
background-color: #ffffe1;
font-size: 11px;
font-family: Arial, sans-serif;
color: #003300;
}
.windowbg3 {
background-color: #cce6cc;
font-size: 11px;
font-family: Verdana;
color: #003300;
}
/* Misc./title/category colors */
.hr {
color: #006752;
background: #ffffe1;
}
/*table border style */
.bord {
border: solid 1 #006752;
}

/* cells top & bottom of news bar */
.titlebg {
background-color: #006752;
color: #ffffe1;
}
/* headings in news bar & elsewhere */
.text1 {
font-style: normal;
font-weight: bold;
font-size: 12px;
color: #ffffff;
}
.catbg {
background-color: #cce6cc;
color: #003300;
font-weight: bold;
font-size: 13px;
}
/* color of cell borders */
.bordercolor {
background-color: #006752;
color: #ffffe1;
}

/* Image fonts */
.imgbg {
font-style: normal;
font-size: 10px;
color: #005177;
}
.imgcatbg {
font-style: normal;
font-size: 10px;
color: #005177;
font-weight: bold;
}
.imgtitlebg {
font-style: normal;
font-size: 10px;
color: #ffffff;
font-weight: bold;
}
.imgwindowbg {
font-style: normal;
font-size: 9px;
color: #005177;
}
.imgmenu {
color: #003300;
font-style: normal;
font-size: 11px;
font-weight: bold;
letter-spacing: 0.1em;
}

/* Post quote/code colors */
.quote {
font-size: 10px;
font-family: Arial, sans-serif;
color: #000000;
background-color: #cce6cc;
}
.code {
font-size: 12px;
font-family: Courier New;
color: #000000;
background-color: #cccccc;
}

</style>
<script language="JavaScript1.2" type="text/javascript">
<!--
if ((navigator.appVersion.substring(0,1) == "5" && navigator.userAgent.indexOf('Gecko') != -1) || navigator.userAgent.search(/Opera/) != -1) {
document.write('<META HTTP-EQUIV="pragma" CONTENT="no-cache">');
}
// -->
</script>
</head>

<body>
<br>
<table width="92%" cellspacing="1" cellpadding="0" border="0" align="center" class="bordercolor">
<tr>
<td class="bordercolor" width="100%">
<table bgcolor="#ffffe1" width="100%" cellspacing="0" cellpadding="0" border="0">

<tr>
<td>
<table border="0" width="100%" cellpadding="0" cellspacing="0" bgcolor="#ffffe1">
<tr>
<td bgcolor="#ffffe1" height="50"><img src="logo.jpg" alt="GOTO-League.com" title="GOTO-League.com"></td>
<td bgcolor="#ffffe1">
<p><font size="2"><span class="bold">
Hey, The Master, </span> you have <a href="http://goto-league.com/.//YaBB.pl?action=im">0 messages</a>.<br>

Jun 2<sup>nd</sup>, 2007, 11:07pm
</font><br></p>
</td>
</tr>
</table>
</td>
</tr>
</table>

</td>
</tr><tr>
<td class="bordercolor" align="center">
<table class="windowbg" width="100%" cellspacing="0" cellpadding="0" align="center" border="0">
<tr>
<td width="100%" align="center">
<table border="0" width="100%" cellpadding="3" cellspacing="0" class="windowbg" align="center">
<tr>
<td valign="middle" class="windowbg" align="center"><font size="1">
<?=$SET['menu'];?>
</font></td>

</tr>
</table>
</td>
</tr>
</table>
</td>
</tr><tr>
<td class="bordercolor" align="center">
<table class="bordercolor" width="100%" cellspacing="0" cellpadding="0" align="center" border="0">
<tr>
<td width="100%" align="center">
<table border="0" width="100%" cellpadding="5" cellspacing="0" class="bordercolor" align="center">

<tr>
<td valign="middle" class="bordercolor" align="center">
<font size="2" class="titlebg"> <?=$SET['title'];?> </font></td>
</tr>
</table>
</td>
</tr>
</table>
<?=$SET['conent'];?>
</td>
</tr>
</table>



includes/config.php



<?php

// includes/config.php

$URL = "http://www.goto-league.com";

?>


includes/menu.php



<?php
// includes/menu.php

$MENU['home'] = "<a href=\"".$URL."/index.php\">Home</a>";
$MENU['register'] = "<a href=\"".$URL."/index.php?action=register\">Register</a>";
$MENU['searchL'] = "<a href=\"".$URL."/index.php?action=searchL\">Search Leagues</a>";
$MENU['searchT'] = "<a href=\"".$URL."/index.php?action=searchT\">Search Tourneys</a>";
$MENU['login'] = "<a href=\"".$URL."/index.php?action=login\">Login</a>";
$MENU['logout'] = "<a href=\"".$URL."/index.php?action=logout\">Logout</a>";
$MENU['help'] = "<a href=\"".$URL."/index.php?action=help\">Help</a>";
$MENU['contact'] = "<a href=\"".$URL."/index.php?action=contact\">Contact Us</a>";
$MENU['reviews'] = "<a href=\"".$URL."/index.php?action=reviews\">GOTO Reviews</a>";
$MENU['addL'] = "<a href=\"".$URL."/index.php?action=addL\">Add League</a>";
$MENU['addT'] = "<a href=\"".$URL."/index.php?action=addT\">Add Tourney</a>";
$MENU['space'] = "]&nbsp;&nbsp;&nbsp;[";

// menu
if (empty($_SESSION['id'])) {
$SET['menu'] = "<DIV style=\"font-size:110%\">[".$MENU['home'].$MENU['space'].$MENU['register'].$MENU['space'].$MENU['searchL'].$MENU['space'].$MENU['searchT'].$MENU['space'].$MENU['login'].$MENU['space'].$MENU['help'].$MENU['space'].$MENU['contact'].$MENU['space'].$MENU['reviews']."]</DIV>";
} else {
$SET['menu'] = "<DIV style=\"font-size:110%\">[".$MENU['home'].$MENU['space'].$MENU['addL'].$MENU['space'].$MENU['addT'].$MENU['space'].$MENU['searchL'].$MENU['space'].$MENU['searchT'].$MENU['space'].$MENU['logout'].$MENU['space'].$MENU['help'].$MENU['space'].$MENU['contact'].$MENU['space'].$MENU['reviews']."]</DIV>";
}
?>


includes/actions.php



<?php
// includes/actions.php

switch($_GET['action']){
case "register":
// module
$SET['module'] = "register.php";
// title
$SET['title'] = "Register New Account";
break;
default:
// module
$SET['module'] = "main.php";
// title
$SET['title'] = "Home";
break;
} // switch

require($URL.'/actions/'.$SET['module']);


?>


actions/register.php


<?php
// register.php
$SET['content'] = "hi";
?>

Taylor_1978
06-03-2007, 04:15 PM
Ummm you'll see in index.php I accidentally had it as "conent" instead of content, but this was after changing it back from body.. I've fixed it to say content but still getting error. Just thought I'd point that out before anyone said it was due to a typo hehe

dumpfi
06-03-2007, 05:27 PM
require($URL.'/actions/'.$SET['module']);You are including a remote file here, because $URL is not a local file path. That means a request is sent to GET the page. The server, where the page is located, will execute the file and the output is sent back and included. This is done even if the file is located on the same server.

And now guess what the output of your register.php is like.

dumpfi

CFMaBiSmAd
06-03-2007, 05:35 PM
Edit: basically says the same as above ^^

Now that we have the big picture. You cannot require/include php code using a http://address.

Your $URL = "http://www.goto-league.com"; causes the require to send a http request to your web server and the page being requested (register.php in this case) is parsed and only any echo/print... output from that file is returned.

To require/include the php code in the file, you must specify a file system path.

Taylor_1978
06-04-2007, 04:55 AM
Perfect! Thank you for all your help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum