Uutiset:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu
Advertisement:

Including Functions

Aloittaja thedawn, elokuu 13, 2008, 02:36:04 AP

« edellinen - seuraava »

thedawn

Hey SMF Community,

I have searched for an answer for this all over the web, to no avail, so I'm comming here hoping for some help :)

I have 2 problems - relating to including files in PHP.

For some background, I am updating a database I have written to work in a multi-school environment. (Instead of each school having their own distribution etc). The database is used for recording and booking interviews etc. My plan is to have 1 file distributed to each site, which then includes the second - control - file. Anyway, on to the issues.

1. Included file not returning Session Variables
My index file is successfully calling the include, but not returning the variables from it.

Index.php:
<?
session_start();
if (isset($_GET['go'])){
$_SESSION['go'] = $_GET['go'];
};
include ("http://thedawn.bigbluegum.com/control.php");
?>
<head>
<link rel="stylesheet" href="sources/emx_nav_left.css" type="text/css" />
</head>
<body>
<div id="masthead">
  <h1 id="siteName"><? echo $_SESSION['school'] ?></h1>
  <div id="utility">Log Off <? echo $_SESSION['name'] ?></div>
  <div id="globalNav"><div id="globalLink"><? echo $_SESSION['topmenu'] ?></div></div>
</div>
<div id="pagecell1">
  <div id="breadCrumb"><? echo $_SESSION['crumbs'] ?></div>
  <div id="pageName"><h2>Parent Teacher Interviews v<? echo $_SESSION['version'] ?></h2></div>
  <div id="pageNav"><div class="relatedLinks"><? echo $_SESSION['menu'] ?></div></div>
  <div id="content"><? echo $_SESSION['content'] ?></div>
  <div id="siteInfo"><? copyright() ?></div>
</div>
</body>


Control.php:
<?
session_start();
mysql_connect(####);
mysql_select_db(####);
$_SESSION['copy'] = 0;

function copyright(){
echo '####';
$_SESSION['copy'] = 1;
};

if (!isset($_SESSION['rank'])){
$_SESSION['school'] = 'A School Data Service';
$_SESSION['name'] = 'Guest';
$_SESSION['version'] = '1.0';
$_SESSION['topmenu'] = '<a href="index.php" id="gl1" class="glink">Logon</a>';
$_SESSION['crumbs'] = 'Logon';
$_SESSION['menu'] = '';
$_SESSION['content'] = '<div align="center"><p>A Log In is required to access this data service<br />';
if($_SESSION['error'] == 1){
$_SESSION['content'] .= '<strong>Wrong username/passsword</strong>';
};
$_SESSION['content'] .= '</p><form id="form1" name="form1" method="post" action="index.php?go=login"><table width="200" boarder-colapse:true><tr><th scope="row">Username</th><td>
<input name="myusername" type="text" id="myusername" /></td></tr><tr><th scope="row">Password</th><td>
<input name="mypassword" type="password" id="mypassword" /></td></tr><tr><th scope="row">School</th><td><select name="myschool" id="myschool">';

$sql = "SELECT `school`, `version` FROM `schools`";
$sql2 = mysql_query($sql);
$sql2 = mysql_num_rows($sql2);

for ($n = 1; $n <= $sql2; $n++) {

$sql = sprintf("SELECT `school`, `version` FROM `schools` LIMIT %s, 1", $n - 1);
$sql = mysql_query($sql);
$sql = mysql_fetch_array($sql);

$_SESSION['content'] .= '<option value="' . $sql[0] . '">'. $sql[0] .' (v' . $sql[1] . ')</option>';

};
 
$_SESSION['content'] .= '</select></td></tr><tr><th scope="row"></th><td><input type="submit" name="Submit" value="Submit" /></td></tr></table></form></div>';

};

echo '<title>'.$_SESSION['school'].' (v' . $_SESSION['version'] . ')</title>';
?>


2. Included file not returning functions.
I have the function copyright defined on control.php, but it produces Fatal error: Call to undefined function: copyright() in /home/content/p/o/l/polardropbear/html/thedawn/index.php on line 22 when run.

Any help greatly appreciated

SlammedDime

The problem is that you're calling the file as if it was being served from a website (including a remote file, as its called (http://)).  When you do this, the file control.php is parsed before it is sent to your script calling it, thus all your script gets its some HTML, zero PHP.  (visit http://thedawn.bigbluegum.com/control.php and what you see is exactly what include() sees.)

What you may be able to do (untested) is to echo all of your information so that if you actually visit http://www.yoursite.com/Control.php and you see all of the variables and such, then retrieve that file with file_get_contents or some other functions that parse files and then use eval() to parse the variables.
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

thedawn

Thanks for the quick reply

I think I get what you mean, I'll have a play and see where I get lol

Advertisement: