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.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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:
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?
How Can I Find Out Parent (including) File Of Included File?
How can i find out parent (including) file of included file? Lets imagine that we want to for example auto_prepend file to each file on our server that would write out the name of file its being executed. I know, i can use PHP_SELF but what if i want to write name of file which is already included? I have a web page and i want on it show its name even if it was included, but not the included page itself is showing name but auto_prepend file to each php file, its duty of this auto_prepend_file to write it out i dont want myself to echo it on each page? do you feel me?
Is A PHP Variable Supposed To Be Seen In A .js File Included Into A .php File
Is a PHP variable supposed to be seen in a .js file included into a .php file? I have a client side javascript code stored in a .js file which is included into a PHP file using <script src="filename.js></script> This code initialises a Javascript variable var u="string"; The string is supposed to be the value of $HTTP_HOST So, when initialise this variable like var u=<? echo $HTTP_HOST;?>; I sterted getting a javascript message Syntax Error Am I doing something wrong, or PHP variables are not seen in included js files?
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
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.
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.
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?
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.
Value Of Variable Shown As "Array" When From Included File
I have this statement to find the latest date that a row was inserted ________ $entry=mysql_query("SELECT contact FROM board ORDER BY contact DESC LIMIT 1")or die ("Query failed:<br>$entry<br>Error: " . mysql_error()); while($myrow=mysql_fetch_array($entry)){ if (ISSET($myrow['contact'])){ $latest = date("d M y", ($myrow['contact']+50400)); } } ________ This reports the value for $latest correctly if the statement is in the document. However when the statement is in an included file the reported value for $latest is ... Array Where am I going wrong?
Check File
I'm trying to find a way to search a text file for a certain key, and there will be one key on each line. I'm hoping it could return 0 if there's no match, and 1 if there is. I'm familiar with this in other languages, but I can't find how in PHP you can read a certain line of a file. I can get most of the code already: $var=0; for($i=1;$i<=file_lines();$i+=1) { if (file_read_line()=="key") { $var=1;}} But I'm sure you spot two probmlems, they are file_lines() and file_read_line(). Does anybody know the proper replacements, or a simpler way?
Check File Age.
I am tring to make a script that i will turn into a cron job. Idealily it would check the age of the file and then figure out if it is more then 48 hours old and if it is it will delete it. i have figured out how to check the age and how to delete the files, but how would i find out if they are 48 hours old?
How To Check If File Exists
Have a look in a folder, check if there is a file and if there is display one thing, if not display something else. example: $result=mysql_query("select * from my_table"); while($row=mysql_fetch_object($result)) { if(fodler/$row->name.txt exists) { display this} else { display thus } }
How To Check For Existence Of A File?
Im programming a shopping cart in php with an administrative back end. My question is this: whenever someone uploads an image for a product, I have to check if an image by the same name exists already. I've done this in perl before with a simple while while(-e "/path/to/$image"){ //do my image renaming here} The -e means while exists this file, keep renaming the current file until it has a unique name. So in php I've never done this before and Im trying to find out a good way to go about doing it. I've looked through the manual and cant really find anything.
File Name Case Check
Has anyone come across a utility to check the case of a filename versus a php page? I develop locally on a windows machine (Know Know) then upload to a Linux and everything works usually works fine.
Check File Type
I use this to check my files type: $fileextension = $_FILES['file']['type']; But it returns the files MIME type, such as image/x-png. How can I get it to check the files actual extension? Such as .mp3 and .zip etc.
Check A File Exists In Another Directory
I am writing a script that will insert a link to the page, but before it does that, it must check to see if the page exists. I can use the file_exists($page_file) function, but it seems to only work if the file is in the same directory where the script executes. My script is supposed to find the script in another directory, but it does not find them and returns false. Does anyone know how to solve this problem?
Check File Size Before Upload?
Is there any way to check file size before upload? The reason for asking is that if a user wanted to upload a large file .. say 10 mb or so .. the script suggested by php manual would require the user to wait until at least the file is uploaded to the tmp directory on the server before checking the size. That is obviously an inconvenience. I have tried google and all sorts of searches but to no avail. Have also tried a little javascript function that copies the file's name (and full path) to a hidden field in the hope that I could use filesize ($fileName) to get the size on the client's computer before it starts uploading. That didn't work either (with error : there is no such file or directory etc.. I assum it is because php is a server-side script and it doesnt or cannot read the clients directory system.
Check File Extension Properly
here's my code. Can't get it to check file extension properly or file size...had it working before but not sure why it's buggy now. } elseif ($photo) { $ext = strtolower(substr($photo, -3)); if ($ext == "peg") { $ext = "jpg"; } if ($ext != "gif" || $ext != "jpg" || $ext != "jpeg" || $ext !="bmp" ) { $focus = "photo"; $msg = "Please provide a valid gif, jpeg, or bmp photo"; } else { $photo_size = getimagesize($photo); if ($photo_size > 25000) { $msg = "Photo must be smaller than 25k."; }}} elseif { etc, etc. } else { dbqueries...
Error Check Before Append To File.
I want to be able to append my httpd.conf file from a web browser to make adding virtual hosts a little easier. I've got a simple form that passes two variables. $virtualhost and $subdirectory. what I want to be able to do is read the file and make sure that there is not already a domain name and subdirectory in the file. Code:
How Can I Check If A File Is Completely Uploaded...???
i've created an application for a customer where the customer can upload ..csv-files into a specified ftp-directory. on the server, a php-script, triggered by a cronjob, reads all the data, imports it into a mySQL database and deletes the .csv-file after the import. so far, so good. but in some cases the cronjobs starts running when the file is not completely uploaded. so a part of the data is truncated. :-( is there any method in php to check if a file is completely uploaded via ftp or not? i didn't find anything about this on php.net and it would be great if someone could help me with this problem.
Check Clientside File Size
i have an upload mechanism on my website and want to check the filesize on the client size. is this possible?
Function To Check If A File Exists Or Not?
Does anyone know if there is a function to check whether a file exists or not? Something like readfile(), but which DOESNT actually output the file. I'm trying to write an upload script, so something like this: if (@readfile("$filename")) { echo "This file exists already"; } else { echo "This file does not exist"; } Anyone know?
Check The File Size Before Upload
I am creating a PHP site where end users are required to upload images. I need to ensure that the end user doesn't upload a file that too big. I can't find a way to set this limitation in the HTML, and checking it using PHP is too late as the file is already uploaded. Is there some JS that I can use to check the file size client-side? (It's also important that whatever JS I use, if any, doesn't contain Js scripts that will be a lot of dectors be considered spyware...I do realise that the end user can disable JS and also that they can alter settings of thier spyware software but if I can't cater for everyone I can at least cater for normal end users). Background: This is for uploading images of houses to a realestate site, a lot of people that use this (including realestate staff members wouldn't or don't resize images prior to uploading.
How To Check/verify File Types?
I'm working on some file uploading code, and need to check the file type and then verify that it's either ".doc, .txt, .pdf, or .xls" -- if it's not one of those, display an error and not upload it. But, I'm not sure how to do this; I think I want to implement $_FILES[my_file_name]["type"] somehow, but I just don't know where to begin or how to implement it??? Code:
Check If A File Is In Windows-1250
i need to check a file to see if its encoded in windows-1250 so ican convert if it is... i cant just convert the files that are in the correct encoding because this adds some strange characters where there shouldnt be does anyone know how i can check? ie if (windows1250($doc)) { iconv(...); } how do i do that check?
How To Check Size Of File Before Upload To Serevr
is there anyway that i can check the size of file on client side before uploading file to server? suppose the user uploads file of 10 mb then the server will know the size is 10 mb after the file is uploaded to server which wastes the bandwidth so what i want to check is that the server first checks the size of file to upload and if it is o.k. then and then only the file will be uploaded..
Problems With Check File Upload Is Jpeg
It seems that the following code works for the majority of my visitors, however for very few, it throws back that the image they upload is not a jpeg, even though it is and we have tested the image it as well with no problem. So its on some computers. Im thinking that there must be a mime type missing, but we can't seem to get it. It varies from Firefox and IE. code:
PHP4 -> PHP5: Require Does Not Check File Directory Anymore?
In my application I have lots of require statements that include files residing in the same directory: index.php requires: require_once($_SERVER['DOCUMENT_ROOT']."/modules/cms/classes/page.php"); page.php requires: require_once("common_functions.php"); Now I try to install the application on a PHP5 server (Apache), and this does not work anymore. In the PHP4 -> PHP5 migration chapter of the manual I did not find any notes on a change of the require/include behaviour, not checking the directory of the calling file anymore; nor did I find it googling. So I am not sure if it is an undocumented migration issue or just a setting. I understand that I can use: require_once(dirname(__FILE__)."/common_functions.php"); But this means rewriting the whole application. Is there a way to change this behaviour via ini_set()? (As I am in a shared hosting environment I have no direct access to the php.ini.)
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?
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?
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.
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.
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...
|