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:
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?
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.
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.
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.
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.
Variables Passed Between Functions
I have a function that fills the value field of a form with 2 possible variables but they are not getting set so when you view source you just see value="" I also try echoing these variables to see if they are getting set but they are not. Is it becuase they need to be set to global? Code:
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.
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.)
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.
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?
Variables Not Passed From Url Or Form To Page
I use a Mac at home running OSX 10.2, and use the Apache PHP MySQL trio for developing and testing sites. I've had very good experiences with this setup and have had no major problems till now. I noticed recently that variables added to the end of the url (the get method, ...url/page.php?var=value) are not passed to the script within the page. Forms using either the get or post method have the same problem. For example, a page named "foobar.php" containing this: Code:
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:
PHP Not Populating Form Variables Passed Through POST Or GET
I"m running: Windows Xp SP2 Apache2 PHP5 MySQL4 Everything seems fine and dandy, and I can do scripting on server side, but for some reason I cannot get data from a form to be put into a variable. I have a simple form in an html page which submits, and in the php script that handles the input, none of the data in the form is going into the variables. My php.ini file does have all the GPC's in place(ie variable_order, the way they get processed).
Eliminating Passed URL Variables For Multiple Listings On A Page
I have a page with a list of several users, each hyperlinked to another page of 'more info' about that user. The hyperlink contains the UserNumber, UserRegion, and UserStatus, and the receiving page picks up the data in the passed URL. This works well, but I'd like to eliminate the passing of these variables in the URL. One way is to make a graphic ('More Info') that can be clicked to submit a form. Each 'More info' graphic from the dynamically created page could hold the UserNumber, but how can I pass several variables with a single click? On some pages, there can be 100+ users, and I hate to have 100+ separate forms and hidden fields. I thought of using session variables, how can I know which user was clicked to set the session variables?
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:
Creating Dir, Copy Files And Pass Variables To 2 Files
I need to create a folder on the server weekly named by the user. To this folder copy the contents of an /Original folder. Inside the new folder edit one of the files to insert a data with a XML path generated in another application, copied (via memory) and pasted within the very first form and passed to the file in question. <param name="FlashVars" value="xmlfile= $lanofile" /> the $lanofile is the value that I need to pass from the form to be read by this file. I have created an form (n.php) that POST the name of the folder to a second file (creatdir.php) everything is cool until I have to edit the third file. How can I pass the value of one of the formfileds to a second file and them read this value as a variable to be consumed as mentioned above? Or actually right whatever is on the third field to this position (not using variables).
Variables And Php Files
I'm working on a web page and I got 2 files who share a same include file where's my function are created but I want to share variables between these 2 pages, hoping via the include file.
Txt Files And Variables
I'm making a script that will email my users upon registration. For the email body, I want to use file_get_contents to shorten the mail function line. If I use a txt file such as reg_email.txt, will variables such as $username still work? I'm developing this script on my computer and I don't believe the mail function works.
Reading Variables From Text Files
I am playing with several text files that have variables stored in two different ways. One text file stores the data like this: hair=brown eyes=green gender=male The other text file stores data like this: hair=brown&eyes=green&gender=male How can I read the variables from the text file and use them in my php program? I know how to write them to a text file, but have no clue as how to read them.
Selecting Files Extsions And Splitting Up File Variables
1. How would I go about selecting the files with sorten extensions i.e in one directory there might b filename.mes and filename.det, and I would like to select only the filename.mes. Once I have done that I would to count to see how many there is. 2. I am going to have in each of filename.mes multiple lines of data, in the following kind of format:- $membername|$title|$email|$html|$inpost|$previewfirst And I am wondering how about I would go about reading each of the variables from the file and putting them in to the variable names above?
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?
How Many Arguments Passed???
is there a function or method, where i can get the number of arguments passed to a function.? i know that there is a function called func_num_args, but it seams that this function have to be called from within the function, and that was not what i wanted.
XML Being Passed To PHP Via POST
I am using macromeda Flash to create anXML object which I pass to PHP. I need to know how to recieve it into PHP so I can process it in PHP. For now all I want to do is display the XML on the screen. To start at the simplest point I am trying this: $my_xml = $_POST; echo $my_xml; Of course all it echos is "Array" If I have tried a few other things, but I am shooting in the dark.
Data Not Being Passed Into Db
I have this code to enter stuff into my db, When someone views a profile it's supposed to add 1 to the views column but it doesn't. Code:
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.
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.
Stopping Spaces From Getting Passed
I have a simple little form that takes the name and a comment, and adds it to a table. I want to know if there is a way to prevent someone from just entering spaces, and having that get entered as their name. I have the if statement check for $name == '' - but the names entered as just spaces get by it.
Can One Get The Name Of Parameters Passed To A Function?
One thing I like about Ruby is the use of symbols when passing function parameters to a function. One thing I dislike about PHP is that if a function has 4 optional parameters but you want to do something with the 4th one, you need to put in something, perhaps empty strings, for the first 3 parameters, even though you've no interest in using them. I'm wondering if there is anyway to emulate the Ruby style with something like this: http://us2.php.net/manual/en/function.func-get-args.php Is there a way to get the parameters as an associative array? A numerically indexed array is just as useless as the normal style of passing arguments.
Array Passed To Dispay_table()
how to process the array passed to dispay_table(). The idea being that i can pass any number of fields in the array and have them output. Any ideas on how this can be done? $sql = mysql_query("SELECT * FROM whatever"); $table = new CreateTable(); $table->display_table($sql, "field1, field2, field2"); function display_table($sql, $fields){ while($result = mysql_fetch_array($sql)){ // I'm trying to get all the values of // the fields array to dispay here. // i.e. $result[field1] }}
How To Process The Passed Value In Php3?
one of my php3 page passes values to another php3 page. "www.mydomain.com/searchit.php3?variable=value" What are the commands to get/process the passed value? both the scripts or PHP3.
Can $this Be Passed As A Method Parameter?
In a class, can $this be passed by reference or value? function setDatabaseObject("MySql", $this) { // some code here checks the name of the // class of the object that is calling this method } For security, and to enforce naming conventions, I'd like for some of my objects to only be callable from certain classes, but the only way I can think for an object to get the name of the calling code is if I had in the $this keyword.
Variable Passed In Through Header
We recently upgraded PHP and variables that were once passed through the URL are no longer recognized. Example: http://www.sun.com/test.php?defectID=2 Within the test.php code: <?php session_start(); $defectID = (int)$defectID; if ( $defectID != 2 ) { // This should not execute, but does. echo "Error: $defectID"; exit; } ?>
Can URL Parms Be Passed To A PHP Script?
Will the following pass parms "Color" and "Contrast" to the PHP script? If so, how does one retrieve the parms within the script? http://xyz.com/script.php?Color=blue&Contrast=weak
Figuring Out When 2 Hours Have Passed
What I'd like to do is this. get a date and time and determine if it has been a certain amount of time since then. For example, I make an entry in the database of 11:00pm, and I want to periodically check, and if it is 1:00am or later, then I would update the database. Any suggestions?
Date Has Passed Function
I have dates in my db which are stored as strings like this 08/01/2007 and i am trying to write a script which either says the date i pass in is in the future or in the past.
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.
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
|