Classes Uncallable From Files Included Inside Functions.
I'm modifying a copy of oscommerce to work with a template system I'm building. This template system basically just includes a list of files in the order they are specified in the database and sets their permissions etc.
It includes the files through a function, which is limiting the included files from referencing objects/classes/anything. Code:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Variable Scope Of Files Included Within Functions
I have a function that selects a file to include, then includes is. The file is including within the function, like so: function include_file($file_name) { [lots of logic here to figure out the path...] require $file_name; return; } My problem is that the file gets included *within* the function, so all the code in the file inherits the function's scope. Any variables declared in the include file are not global -- they're local to that function. Is there any way around this? Is there anything I can put in the included file or in the function to make sure that variables declared within it are global? (I can't just reference the variables before the require, because I have no way of knowing what's in the include file.)
Calling Included Remote Functions
I have central.php, which consists of this: <?php function square($num) { return $num * $num; } ?> at outerdomain.com, I have test.php, which consists of this: <?php include "http://www.centraldomain.com/central.php"; echo square(4); // outputs ཌ'. ?> outerdomain.com/test.php = "Fatal error: Call to undefined function: square() in blah/blah/test.php on line 12" wha'appen'? I thought you could call included functions? Hmm... if I put central.php on the outerdomain.com, it works. No calling functions from files included remotely?
Using Classes Inside Of Other Classes
I'm wondering how to use another class inside a preexisting class, without passing the constructor in the preexisting class an object from a file that contains a new declaration. IE: Instead of doing something like this...
Classes Vs Functions
I've been using functions since I first started using php, but I've been hearing more and more about classes, which I never really looked at that much. I understand the whole OO programming aspect, but are there any advantages to having classes as opposed to just functions? I've heard that the classes are better because they only load the functions they need to, where with an include file of functions, the whole page gets loaded, even if you only use a couple functions on a certain page. I've searched around and can't find any "official" mention of this though. So, is that true and should I start migrating to using classes instead of functions?
Classes And Functions
I'm trying to get a simple function to work with MySQL inside a class. Below is the function that won't work properly. Can anyone tell whats wrong with it? Code: function query() { $query = "SELECT * FROM pork ORDER BY id"; $result = mysql_query($query, $connection); for ($i=0; $i < mysql_num_rows($result); $i++) { $pizza_name = mysql_result($result, $i, "pizza_name"); $pizza_desc = mysql_result($result, $i, "pizza_description"); $reg_price = mysql_result($result, $i, "reg_price"); $lge_price = mysql_result($result, $i, "lge_price"); echo'<tr><td width="90%" bgcolor="#000000" valign="center">'.$pizza_name.'</td>' echo'<td width="10%" bgcolor="#000000" valign="center" align="center">'.$reg_price.'</td></tr>' } echo '</table>' } I have tried to use an argument for the query function ie. query($table) and used this variable in the mysql statement with all differnent kinds of syntax but nothing seems to work. On the page that calls this function, the error message i get is... Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /var/www/html/class_table.php on line 17 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/html/class_table.php on line 19 Can someone help me please?
Same Variables Used In 2 Included Files
I have 2 seperete files I am including into a script. They uses the same verriables however I want one to execute and then the other. will this be a problem?
No Error In Included Files
The problem is pretty simple. If I include a file <? include 'libs.php' ?> and this file contains an error (a missing ;), my php installation does not tell me anything. I simply receive no output.
Classes Vers. Functions
I've been using static class functions as a means of grouping certain functions together (e.g. class::function() ). Anybody know if this carries a performance overhead beoynd the simple function outside a class?
Plugins - Use Functions Or Classes?
I'm just in the process of planning a new site and am looking to develop a basic plugin system. What I'm wondering if anyone can tell me the best way to do it - if the plugin files themselves should simply be functions that are just called straight in, or would it be better to make a class that encapsulates all of the functions for the plugin?
Classes Calling Functions Using :: And ->
I can call a class using "->", but it complains about the ::. I see on the net where :: is used. Is there a good explanation on when to use one over the other or the differences? $help = new help(); $help->foo(); $help::foo(); class help{ function foo(){ echo "test"; } }
Calling Classes And Functions
I have a variable as $subject=$_POST['subject'] then how do i call a class (so all functions are executed within it) and how to call individual function of the class. I want to pass $_POST['subject'] to the class / function The name of the class is class popoon_classes_externalinput and it contains two functions static function basicClean($string) and static function removeMagicQuotes($data)
Session Data In Included Files
How does a script access the variables in a session file? Scenario: <?-- this is the main script include("main.inc.php") $Username = $myname //myname is a variable in the session file $html = new html; //html class defined in main.inc.php sneds out headers and so on do lots of other php stuff $html -> send_footer() // found in main.inc.php and itself 'includes' footer.php ?> Now footer.php 'included' from within the function send_footer defined in main.inc.php and called by the primary script wants to access $myname, the session variable that stores my user name. i can't seem to get it at all. Has anyone any idea or am i being too vague here? Do I need to do something else at the beginning of footer.php that 'gets' the variable again from the session file? If so, how? The session ID is accessible to it cos I had it print it out to make sure, and the session file does definately hold a variable of the right name, I just can't return the data for some reason.
Passed Variables In Included Files
I'm looking for a guide on how variables are handled in included files. A pitfall I've run into is that if I define a variable, then include a file, the variable can be displayed on the included file. But if I try to call that same variables on the included page within a function, the variable is undefined. Example: PHP Code:
Registering Sessions Inside Of Functions
I am making a login script for my site and am having a buttload of trouble with trying to register a session inside of a function. I am new to working with functions. When the user logs in, the script goes to a function which loads the u/n and p/w into a session. PHP Code:
PHP Code Inside Java Functions ...
I'm trying to build a web based application that will mimic a production scoreboard used on a manufacturing floor. Basically what these scoreboards do is show a daily production goal for how many units to build, show how many units should be off the line by whatever time it currently is, show how many actual units have gone off the line (actuated by pushing a button) and finally shows a + or - variance. (Like we are up by 10, down by 3, etc) Anyway, I have a basic framework already setup which involves several scripts and a database to hold each days build total. However the part I'm having trouble with is a way to build a display function which can be left on all day long, every day. Now unfortunately web sites just aren't meant to stay open and active for long periods of time. My original display page basically stayed inside a while loop and kept updating the numbers on the display, however eventually the browser just gives up and stops loading the page. So my question is, are there any tricks to let my do some PHP code inside of java functions? That way I could use java time functions to do a loop and I think the browser would be more accomodating. However I don't see how this could work, as once the page is loaded I'm not sure you can do anything with PHP anymore. Anyone have any thoughts or anything on all of this? Keep in mind the overall goal is to have a page that can be left fully unattended for over 8 hours at a time (preferabbly "forever") but keep checking a DB entry in a MySQL database every so many "specified units of time".
PHP Does Not Recognize PECL Classes/functions
How do I get PHP to recognize PECL-based classes and functions with the following environment: PHP 5.2.0 Windows XP I have php_fileinfo.dll in my extension directory, referenced in php.ini, however, PHP has no clue what any PECL-based class or function is, unless I use CLI PHP and then it only recognizes the functions and not the classes.
Is Php Case Sensitive With Functions/classes
I was just wondering because i have in the past done $db->getall() where it really is $db->getAll(); but get not error. I just want to know because i want to include a different database class that i have created that has some more functionality than the current database class and the current database class is named Database and mine is named database, would that cause a conflict?
Sending Queries & Variables Across Included Files
I'm working on a template parsing engine of sorts. Basically the way it works is, depending on how a variable is set, a file is included. The file is an entire page containing HTML and PHP, starting at the <html> tag. What I had planned on doing was writing a query for that specific type page. For instance, on "index.php" I have my connection script, and on "include.php" I have the while($row = mysql_fetch_array($query)) loop to actually display what results the query got. Problem 1: Unless I write the query into a variable on include.php, I get an error. The error states that the query isn't a valid MySQL resource, but I know for certain it is, because if I write the exact same query on the included page with the exact same connection script, it works fine. Problem 2: For files that are included off of the included page (for example, I have an include on include.php that links "homeslice.php" to the page), I have to use the full path (http://mysite.com/ect/homeslice.php) rather than just the site path, (/ect/homeslice.php). My question: Is there a trick to getting these things to work the way I want them to, and if so, could someone please let me in on it?
Confused About Scope Of Globals In Included Files
I'm having an issue where what should be global variables are not in scope and I'm confused as to why. In Case 1 the variables are not in scope for functions in File2 In Case 2 the varibales are in scope for access in File1's functions AFTER the include In Case 3 the varibales are in scope for functionsin File2 Why does case 1 not work but case 3 does? Does case 2 the proper method to use? CASE 1:.........
MySQL Transactions Doesn't Work With Included Files?
I have a situation where I open a database connection in main script. Then I start a transaction, have some queries, include an another php file within some queries and then commiting queries in the main script. All queries in the main script gets committed but those in the included file doesn't. Why's that? Adding COMMIT query to the included file doesn't work either. Here are an test code which clears what I mean: the main file (test.php): <?PHP $db = mysql_connect ("localhost", "dbuser", "dbpass") or die ("Database connection error!"); mysql_select_db("databasename") or die ("Database selection error!"); mysql_query("START TRANSACTION", $db); mysql_query("INSERT INTO news VALUES (NOW(),'author','message from main script')", $db); include "test2.php"; mysql_query("COMMIT",$db); mysql_close($db); ?> and the included one (test2.php): <?PHP mysql_query("INSERT INTO news VALUES (NOW(),'author2','message from the included script')", $db); ?> So, this script runs fine, but there is just one row inserted to db (the one from the main script (test.php)). var_dump of $db in the included script tells as it should: resource(2) of type (mysql link) Tables are InnoDB type and START TRANSACTION and COMMIT both returns true (1). I also made some error handlers but those were not trapped either.
Session Variables Do Not Persist Into Included Files
In my index.php file I set a session variable $_SESSION['product'] = "foo"; and then in my html part of index.php I include a file menu.php using require_once() which I use to build the menu tree. However, the session variable is not available to me inside that include file. It is available to me inside index.php because if I echo it I can see it. If I go to page2.php it is also there. Just not in the include file.
Files Not Being Included With Set_include_path() Or Ini_set('include_path')
I cannot seem to wrap my head around this peculiar problem. I have tried using both the function to set my include path, and then echo the get_included_files() and the files do not appear in the array. I can use require() or include() with no problems, but when I try to set the include path, the files do not seem to be included. Is there some weird quirck or gotcha to using this feature of PHP? I thought all you have to do is provide the directory and viola it should work. Any advice?
'exactract()'ing Functions, Classes, Etc. Into A Template System
Well I ditched my idea to load, store, and eval() templates from files as it has some serious security issues, and decided to go with a much simpler approach: class template { public $theme = "default"; public $theme_dir = "themes/"; private $templates = array(); private $vars = array(); private $errors = array(); private $cwd = ""; function template() { $this->cwd = getcwd(); } .....
PHP Varibles Inside Template Files?
I have a template file that has some PHP variables inside of it. I would like to pass through the template and evaluate any variables inside the template file. I have "tags" around the PHP variables. <<TEMPLATE FILE>> blah html code <MARKER>$variable1<REKRAM> blah html code I can write PHP code to go line by line through the code to find the "marked" code. $myLine=preg_replace("/(.*?)<MARKER>(.*?)<REKRAM>(.*?)/","$1$2$3",$myLine); The above code works fine in removing the "markers" but it does not evaluate the PHP variable. How do I eval() $2 (the PHP variable)?
Storing Classes In Text Files
is there a way to store class in a text file? and then recall thjem? and is there a better way to store variables and such than a text file, so its unreadable? what i mean abou my question is.. is it possible to make two classes: User1 and User2, and then recall them so you can get User1.password and User2.password, User1.ID, User2.ID, etc.
Problem With A File Included Twice When I Want It To Be Included Once
I have a problem with a file that apparently is being included twice when I want it to be included once. I searched all my files and couldn’t find a place in which I am not calling it with include_once("file_name") Is there a way to print or output in any way which file calls this file? It could be an included file that calls this file, so I need to know the file name, not the page name that calls this file.
Included File Not Included Every Time
I have some pages where I'm including a header for the document - beginning of the HTML, style sheet, javascript, logos etc. The problem is that sometimes it's being included and sometimes it isn't - and I'm talking even on the same page. The header file is in the same folder as the document I'm including it in, so I'm just using: PHP Code:
Files Inside Files
im creating something new with alot of php files, and i remembered that alot of times on message boards and things like that you see like "misc.php?action=list" or something like that. i would really like to decrese the amount of files i have for this new thing im creating. can someone show me how to put multi files in one?
Functions For Num Subdirectories And Files In A Directory?
Are there php functions that get the number of subdirectories or files in a given directory? I cannot locate one. If so, is it fast? I plan on having a lot of files/directories, so I just want a number, not a list. The server people tell me that only approx. 32000 subdirectories can be in any given directory, so I want to switch directories when it starts getting near that limit. This is thinking way ahead, but I would rather plan for it now than encounter problems later.
Static Classes Vs. Singleton Classes Vs. Globals
Sometimes I want to use certain data and functions anywhere in my code; for example, when writing logging routines. In PHP5 I could write a class with all static members and functions, a singleton class, or a regular class assigned to a global variable. What would be the advantages of each? In Java web-apps (or in non-web applications), these classes persist for much longer, so it's easier to see the reasons for using them. But in PHP, it seems like you could do pretty much the same thing with all three.
Why Is /php/php.exe/ Included In Url When Using $PHP_SELF?
For some reason when I run $PHP_SELF in a script the url it returns includes /php/php.exe/ between the root folder and the actual php file from which $PHP_SELF originated. how to get rid of this so it shows the normal directory structure?
DBM Functions:: Undefined Functions Error
I have been trying to use the DBM Functions (dbmopen etc) in php but always get an undefined funtion error. Do I need to load something or change something in the .ini file to get it to work? thanks MIke
Change Included Code
Can I modify code that I have included using <?php include("../Index.php"); ?> The Index.php file contains links that need to be modified to work. Index.php is basically an html file uses a linked css file and when its included in the new file its referencing a css file in the wrong spot. I need to add "../" to the css file reference in Index.php to make it work.
Check If A File Has Been Included Before?
I want my scripts to be warning and error free. Is it possible to check is a file has already been included as part of a "require", "require_once" or "include" call in the script? I guess I could just include everything and turn warnings/errors off, but I'd prefer not to do that.
Included PHP Code Not Parsed!?!
On a hired webserver, the php code that is in the files included with 'include_once' and 'include' command is not parsed. The php file which includes these parses just fine. The included php is also parsed just fine on my test apache. Example: Request 'www.myurl.com/page.php' on the browser, it runs correctly, including the file 'menubar.inc' into the outputted content. The file menubar.inc contains html and php, in the following manner: <img src="img/LogoV<? echo $tmp; ?>.png" border="0" /> On my test server that would be parse to, for example: <img src="img/LogoV4.png" border="0" /> Thus displaying an image. BUT, on the webmotel the html comes out without parsing, as: <img src="img/LogoV<? echo $tmp; ?>.png" border="0" /> :( ? I would ask the customer service, but I know it will take +10 days to get the answer.
Included Variables Are All Blank.
This is the first part of myblog.php, which is the page you see in the browser. <?php require("/home/www/htdocs/master.php"); //functions are in here $u = "test"; //username $htitle = "Test blog!"; //for <title> //includes dbcon(); //connect to database blog($u); // START PAGE echo $welcomemessage;Functions are in master.php. It calls function dbcon, which logs me into MySQL and selects the database. It calls function blog: function blog($u) { //not using $u for anything yet. require($path."blog/vars.php"); require($path."blog/head.php"); }Vars defines stuff needed for the blog, Head is the header, with <html>, <head>, etc. $welcomemessage is defined in vars.php, but it doesn't show anything when I echo it in myblog.php. I went into vars.php and made it echo in there, and it worked, so it is defined correctly and the file is included, but for some reason the variable goes blank by the time I get back to myblog.php. It's the same with all the arrays I defined in there too.
Feed Included URL Into A Variable.
I need to access a page (CGI) on a different server. I can do this fine with an include and that will display all the info I need on the screen. The problem I face is that I actually need to parse through that info. When i try assigning it to a variable... $dogggg = include ("$SpecialString");...the variable is always "1". $specialString is the URL Clearly what I am doing is wrong but if someone can please point me in the right direction for what I need to do in order to get that output into a variable so that I can parse it, do what I need to with that info and then display it.
Running Php Included From A Mysql Database
I'd like to include php-code out of a mysql (or odbc) database on a php-page and run that code. Is that possible? I know howto include normal text(&html) from a database to a php-page. But I'd like to work with templates, therefore in need just a little bit php-code in my database. (and included on my pages).
Passing Arguments To Included Php Script
I am working on a server that does not allow PHP to be embedded into documents unless they are in the cgi-bin directory. This is annoying but I've been working around it with wrapper pages in other directories that contain only <!--include virtual="/cgi-bin/relevant_script.php" -->. One of my scripts is more difficult to work with because it is a collection of links, each of which points to the same script with different arguments. It is not acceptable to my boss to go to a URL like mysite.com/sub/script1.html (which just includes a script in cgi-bin) and have that link to mysite.com/cgi-bin/script2.php?arg1=blah . I want to have the script included in script1.html to link to another wrapper page that takes arguments (script2.html?arg1=blah) and have the included script take those arguments...
Retrieving Variables From Included File
I'm trying to use a variable created in a file I'm including from within a PHP script: include("http://www.domain.com/script.php"); echo $variable; // $variable still empty? The $variable is created inside script.php but is empty when I echo it from the calling script. Is it the way I'm including the script via http? I have to do this since it's on another server.
Establishing PHP Session ID In An Included File
Forgive me if this doesn't make too much sense but I've been working on this project all day and my brain is a bit fried. To make some of my code more readable I made a file (called urls.inc) which I include in my PHP scripts. This file contains functions to return a URL with the session id tagged on the end. I've now found out that the session id returned by the functions in urls.inc is not necessarily the current, and more importantly correct, session id. I need to know if there is a way to establish the current session id within the included file. For info, I've built the scripts so that the session id is passed from page to page to avoid using cookies (part of the challenge, it's a college project) so I need the urls.inc file to know which session id to pass back otherwise it all goes a bit squiffy. Here's urls.inc : <?php session_start(); function logoutURL() { return "logout.php?PHPSESSID=" . session_id(); } function adminURL() { return "admintools.php?PHPSESSID=" . session_id(); } function homeURL() { return "main.php?PHPSESSID=" . session_id(); } ?> These are called like this : echo "<h3 align="center"><a href="" . adminURL() . "" target="mainFrame">Administration Tools</a></h3>"; If it turns out that there's no way to do what I'm after then it's not big deal because I can change the URL line to : echo "<h3 align="center"><a href="admintools.php?PHPSESSID=" . session_id() . "" target="mainFrame">Administration Tools</a></h3>";
Stopping Execution Of An Included File?
I have a structure like this: Code: /index.php /dir_1/index.php /dir_2/index.php . . /dir_n/index.php In the topmost index.php file i have a switch statement selecting the current active directory (e.g. dir_2) and including the index.php file in that dir, if it exists. Is there any way I can stop the execution of the included file (/dir_2/index.php) without affecting the calling file (/index.php)?
Getting Cookie From HTTP_COOKIE_VARS In Included File
There's this thing about cookies that's bothered me and up until now I simply got around it. I can't do it anymore right now and I need to solve this problem, so I'm asking for some help. I have used the include() function to include a few PHP bars and modules in a main PHP page. I can get cookies with the HTTP_COOKIE_VARS or $_COOKIE globals in the main page, but not in the included ones. If I open the included PHP pages as standalones, I can get the cookies. I already had tons of problems with include(), I guess this is just another one. Can anyone tell me if it is supposed to be so (PHP manual says I can access the related global from anywhere) or if there's a way to fix this. The one thing I can't do is reading the cookies from the main page and passing them to the include, because that would mean changing code for the whole site.
BOF In The Included File Shows Up In The Browser
I have an UTF-8 PHP file which generates HTML Then I cut the beginning of that file, pasted into another UTF-8 file ind included this second file into the first one. After that the whole page moved down about one libe leaving a gap at the top of the browser window. Viewing the resulting code of the first file via VIEW-Source, I and see a square inserted before the included file. This does not show if I open the included file with a Unicode supporting text editor. A non-unicode editos shows i>? at the beginning of the file which, I understand, is BOF. So the problem is that the browser sees the second BOF and displays it as a small square in a separate line
Included File Not Loading Completely
This is my first post to this list, so forgive me if this is very basic. I have a file: overview.php that is including another file dolan_header.php I have tested it on three servers...on two of them it works perfectly, and on the third (the client's server) the header file fails to load the first ~12 lines of code. A functioning version of the page is here: http://64.132.144.101/~somedom/dolan/overview.php And a malfunctioning version is here: http://dolanconcrete.com/staging/overview.php I have placed the two PHP files here if anybody should care to inspect them. http://64.132.144.101/~somedom/php/dolan_php_debug.zip
|