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.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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?
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.
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:
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?
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.
Dynamically Concatenate Variables Without Leaving A Blank Space
The $match1 value below is part of a Select statement. The user, by checking a checkbox on a form, determines whether the $Topic, $Subtopic, and $Theswords variables have a value or not. If the variables have a value, the variable is added to the Select statement. If a user selects all of the variables, the Select statement executes properly. However, if only one or two of the varables are selected by the user, I get a syntax error because the Select statement contains a hanging comma as shown in the Select statements below. Code:
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:
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?
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.
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.
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...
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.
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.
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
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?
Require_once Fails If File Already Included
I am having a problem with multiple includes. A.php require_once on two files: B.php then C.php C.php require_once on B.php again Then I get a message: Warning: main(../../B.php): failed to open stream: No such file or directory in /home/jkennedy/public_html/foo/php/secure/common/A.php on line 1 Fatal error: main(): Failed opening required '../../B.php' (include_path='/home/jkennedy/public_html/foo/php/secure:/usr/share/php:/usr/share/php/Smarty-2.6.2/libs:/home/jkennedy/public_html/foo/_php/secure/PEAR') in /home/jkennedy/public_html/foo/php/secure/common/A.php on line 1 If I comment out the second require_once of B.php in C.php, the error goes away and I still get the variables defined in B.php, so I know it is being included. My question is why is it failing in the manner that it is doing? From what I could tell in the manual require_once was supposed to do nothing if it was already included. And why the "Failed opening", as if the file didn't exist? I am using PHP 4.3.4.
Open Link In Included Page
How to include Link that could open in same page rather than going to another page for example, if i include a file in home.php <? include("/index.php") ?> and I want to open up the LINKS in "index.php" in same home.php. example - open "/index.php?p=Hits" on same home.php page I know i could have FRAMES but i dont want to frames in my site
Printing The Line Number And Name Of Included File
Does anyone know how to echo the line number and included file name in php. I like to use development tags but sometimes I forget what included file they are in and what line they are on. I use a master variable to turn off all of the dev tags, but I would really like an easy way to automatically print the line number and file where the function is. This would be like if there was an error, but with out breaking the script and with out generating a nasty error.
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.)
Getting An Included PHP Script To To Include A File In The Same Directory.
I am a little stumped at why when I try to include a file in same directory as the script being processed, it looks in the same directory as the script that included it to begin with. Is there any way I can get around this? Is there anyway to get the name and/or of the script being processed, rather than the name and/or path of the script that was first called?
Included Templates Have Trailing Unwanted Characters
I have a script that opens a template file, reads through the file line by line printing each line. If a line contains a certain string, then that line gets replaced with a second template file. Unfortunately, the second included file always contains extra, unwanted characters that change everytime I refresh the page. I couldn't find anything related in the FAQ, Code:
Original PHP Configure Included APXS, Not On My Machine
phpinfo() (4.2.2) shows that the configure flags included --with-apxs2=/usr/sbin/apxs There is no apxs program/file on my computer. httpd -l shows mod_so.c , so DSO is definitely compiled into the binary. Trying to upgrade PHP with the same configure flags gives the error "Sorry ..." can't find apxs ... and why should it? It's not there! :) So how could the current installation have configured successfully?
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:.........
Check User/password On Included Pages
if i have itlike tihs: login.php checks the username and sets $_SESSION[] variables login to 1 username to username and password to password: then it takes you to main.php. all that one does is include navigation and all the content. if the link is clicked. it also checks if the user's logged in. what i am wondering is. all the pages that are to be included. is it ok not to check username/password on them and only check if the variable $inc exists. that variable is set on main.php, plus the include pages dont have session_start() on them. will that stop people from accessing them individually? they cant fake variables right?
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.
How Do You Access An Array In An Included/required Field?
I have a large array that would be messy to include in the file "main.php" itself and would prefer to include/require it. Say I have the following line in "main.php": require_once('/arr.php'); And the "arr.php" file looks something like this: <?php array(1)='ok1@Ok.com' array(2)='ok2@Ok.com' array(3)='ok3@Ok.com' array(4)='ok4@Ok.com' array(5)='ok5@Ok.com' array(6)='ok6@Ok.com' array(7)='ok7@Ok.com' array(8)='ok8@Ok.com' array(9)='ok9@Ok.com' array(10)='ok10@Ok.com' ?> Would I be able to reference the array AS IF I had declared the array in "main.php"?
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?
Reloading Page From PHP Script Included With Javascript
I have a page with a div which is filled with content from a PHP script via javascript and innerhtml. Sometimes, depending on the results of the PHP script, I want to to reload the entire page, not just the div . However if I put a PHP redirect in the script, it just loads the entire page into the div.....
Fopen And Filename As Array Element (code Included)
i have a piece of code that reads a csv list. For instance: 1,index.html 2,linux.html I read these in an array and then i want to use the filename (2nd array element) to make a file and write something in it. However, i always get the error: Warning: fopen(index.html ): failed to open stream: Invalid argument in E:DATAstartpagegenerate.php on line 34 Cannot open file The code that gives problems is this and more specificaly the titel var if (!$file_handle = fopen($titel,'a')) { echo "Cannot open file ".$titel; die; } If i for instance change this $titel to "index.html" then i do not get warnings. So it probably has to do with how $titel is presented. I tried wrapping $titel in double qoute, that doesn't work either. I tried wrapping $titel in single qoutes but that off course uses $titel as the name of the file instead of the content of the variable. How can i make this work? Code: ==== <?php $PAGES = "pages.txt"; $data = 'This ' $data .= 'is a ' $data .= 'string.' /* open pages parse them and make the pages */ $file = file($PAGES); foreach ($file as $line) { $arTemp = explode(",",$line); $aPages[$arTemp[0]] = $arTemp[1]; echo "Making ".$arTemp[1]." with id ".$arTemp[0]." "; unset($arTemp); } foreach ($aPages as $sleutel => $titel) { print "Huidige waarde van $aPages: $sleutel, $titel. "; /* write file*/ if (!$file_handle = fopen($titel,'a')) { echo "Cannot open file ".$titel; die; } if (!fwrite($file_handle, $data)) { echo "Cannot write to file ".$titel; die; } fclose($file_handle); } ?>
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:
Database Connection Problem In Included File On Root Directory
I have a file called tophtml.php that connects to the database. It's in the root directory of the site. It works perfect in the root directory. But if I call it in a sub directory. (e.g. require("../tophtml.php") or require("C:websitesdogrealm ophtml.php")) I get errors saying it can't connect to the database.
OOP Page = Blank
OOP – page does not display I need your keen eyes to figure out what is happening here I have an OOP script that works well on two local test servers One runs a slightly older PHP, the other one the last PHP just before release of PHP5, in both cases it runs with Reg Glob off, as it should How is it built: One) A class that reads a template, sets values, and sends info to a browser. That class I have used many times and I know it does not cause any trouble Two) a templates Using the following <!--{PROD_1}--> no problems here! Three) the main page << require_once ("../DB conn etc..."); // Include the configuration file. require_once ("../classes/the class I mentioned in “One”.class"); // Include the class. $id=1; $page = again the “One” class ("../templates/main_template_products.inc.php"); // Create an instance. $content_1 .= '' include "../includes/prod_1.inc.php"; $page->SetParameter("PROD_1", $content_1); and my include file <? $conn = db_connect(); $sql= "select prod_1 from XXXXX where id=$id"; $result = mysql_query($sql,$conn); while ($new_content=mysql_fetch_array($result) ){ $content_1.= $new_content[prod_1]; } ?> I am pretty sure that the scripts has no fault. It works on another production server. So what can go wrong. Up to the point of getting a full blank page that in “view source” shows 100% of nothing! I know the DB conn fine since I can edit it via my CMS using the same db conn function. Will that be a server setting? It runs with reg glob on and safe mode on.
PHP 4 W/ IIS 6 = Blank PHP Pages
I've installed PHP4 in isapi mode on Win2k3/IIS6. When I try to access a PHP page, it comes back blank. The odd part is that if I just a test page with phpinfo() in it, I get results. I've tried everything and spent the last 2 hours googling for a solution. Any ideas on why this would be happening?
Drawing A Blank...
I was wondering what the most efficient way to extend a session lifetime was? Do I use ini_set() to change the session lifetime or is there a specific session function that handles this... Checked PHP.net and I am drawing a blank..
Blank Pages
I have a web site that uses session variables and cookies. In-house and at most clients the web sites functions great, exactly how it should behave. However, at a few sites, the users will get the login page and as soon as they submit, they get served a page with just the banner image on top and blank underneath it. The page is two frames, top and bottom with the banner image on the top. When viewing the source, the bottom page contains <html></htmlonly. Looking at my PHP scripts, there are no scripts that could generate that kind of a blank page, it would at least have a <headin it. So far what I've found that's different between the sites that work and the one that doesn't is as follows. The machine name is SQL1 with an IP address of 10.1.1.100. On this machine is a web site set up in IIS with an IP address of 10.1.1.150. All of the users at this site use a url of http://statuspage.cosite.com to get into the site. If you use a URL of http://SQL1/statuspage/userlogin.php - everything works fine. If you use a URL of http://10.1.1.100/statuspage/userlogin.php - everything works fine. If you use a URL of http://statuspage.cosite.com - They get the blank page after the login page. I'm thinking it has something to do with domains and cookies but I'm not sure. My cookies are set as: setcookie("UserKey", $UK,$expiretime); setcookie("PHPSESSID",$_COOKIE["PHPSESSID"],$expiretime); $expiretime is a variable containing the expiration time of the cookie
PHP Blank Page.
I posted earlier about this, a blank php page. I've enabled logging ALL in the php.ini, but nothing. If I change the name of the db in the include file, I get an error message, so I guess this means it's connecting to the mysql db. I've included the first couple lines of code for this page: index.php <?php session_start(); require_once('inc/db_config.inc.php'); $conn = db_connect(); $sqlsu = "SELECT * FROM subjects ORDER BY ID"; $ressu = mysql_query($sqlsu, $conn); if (mysql_num_rows($ressu)) { while ($qry = mysql_fetch_array($ressu)) { $cat = stripSlashes($qry['cat']); $resns = mysql_query("SELECT * FROM questions WHERE test LIKE '$cat'", $conn); $numcat = mysql_num_rows($resns); inc/db_config.inc.php function db_connect() { $result = @mysql_pconnect('localhost', 'root', 'password); if (!$result) return false; if (!@mysql_select_db('quiz')) return false; return $result; } ?>
Getting A Blank Page?
When I try to run a PHP script of mine, I get a totally blank page. I've tried to put HTML at the very beginning of it, but even that does not show up. I don't see anything wrong with it either. Basically there are two header requires, and then some code that reads a database, and then a few more requires.
Blank Page?
I hve index.php setting two session variables when you login. But when i put session_start(); on any other page to get the variables, it leaves me with a blank page. What could be causing this?
Blank Page
I tested this php form, and it worked on 2 out of three computers, all of which were on different networks. The one that didn't work stalled after I hit submit . . . all I got was a blank page . . . no error messages or anything. This happened whether it was on a PC or Mac, in Firefox, or IE. Any ideas what could be causing it? Code:
|