473,835 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling external php file before <html> tag

Ben
hi all,

just wondering if it is possible to call a function that resides on
external php file before any <html> tag?? i have a code that sets a
cookie which needs to be called before <html> tag. If I use that code
on the same file, it works fine. But I'd like to use it on a separate
php file so that it'd be easier to modify in the future because that
same function can be called from other files too... When I include the
external php file in my main file, it gives me warning saying
something like the cookie is set by the external file.... Is there a
way to do it properly?

Thanx
Ben
Jul 17 '05 #1
5 3059
include("file_p ath/file_name.php") ;
function_name(a rg1,arg2,[...],argX);

Basically, you include the file, then call the function contained in the
file.

-Wes

"Ben" <cr*********@ya hoo.com> wrote in message
news:d9******** *************** ***@posting.goo gle.com...
hi all,

just wondering if it is possible to call a function that resides on
external php file before any <html> tag?? i have a code that sets a
cookie which needs to be called before <html> tag. If I use that code
on the same file, it works fine. But I'd like to use it on a separate
php file so that it'd be easier to modify in the future because that
same function can be called from other files too... When I include the
external php file in my main file, it gives me warning saying
something like the cookie is set by the external file.... Is there a
way to do it properly?

Thanx
Ben

Jul 17 '05 #2
Shit. Wasn't thinking all the way again. You can shoot me if you want! A
warning isn't necessicarily saying that you've done something horribly
wrong. It's just informing you of something that could be potentially
hazordous. There is a setting in PHP.INI that allows you to stop the
warnings.

Please feel free to correct me as needed.

-Wes

"Ben" <cr*********@ya hoo.com> wrote in message
news:d9******** *************** ***@posting.goo gle.com...
hi all,

just wondering if it is possible to call a function that resides on
external php file before any <html> tag?? i have a code that sets a
cookie which needs to be called before <html> tag. If I use that code
on the same file, it works fine. But I'd like to use it on a separate
php file so that it'd be easier to modify in the future because that
same function can be called from other files too... When I include the
external php file in my main file, it gives me warning saying
something like the cookie is set by the external file.... Is there a
way to do it properly?

Thanx
Ben

Jul 17 '05 #3
Ben
"Wes Spikes" <Mo******@NOSPA Mverizon.net> wrote in message news:<3GdYc.640 $O85.477@trnddc 05>...
include("file_p ath/file_name.php") ;
function_name(a rg1,arg2,[...],argX);

Basically, you include the file, then call the function contained in the
file.

Thanx Wes!

That's exactly what I did but it doesn't work...
My external php file is below (this sets a cookie):
<?php
function counter() {
$cookie_val = @$_COOKIE["user_ip"];
$counterfile = "counter";
$line = @file($conterfi le);
if(!$cookie_val ) {
setcookie("user _ip", "$_SERVER[REMOTE_ADDR]", time()+36000);
if ($line[0] == NULL) {
$line[0] = 0;
}
$line[0]++;
$cf = @fopen($counter file, "w+");
fputs($cf, "$line[0]");
fclose($cf);
}
elseif ($cookie_val != "$_SERVER[REMOTE_ADDR]") {
$line[0]++;
$cf = @fopen($counter file, "w+");
fputs($cf, "$line[0]");
fclose($cf);
}
}
?>

My main (calling) php file is like this:
<?php
include 'phpfunc.php';
counter();
?>
<html>
<head></head>
<body></body>
</html>

I get the following warning:
Warning: Cannot modify header information - headers already sent by
(output started at D:\Apache Group\Apache2\h tdocs\phpfunc.p hp:26) in
D:\Apache Group\Apache2\h tdocs\phpfunc.p hp on line 8

I also uncommented "include_pa th" in php.ini and added the path to my
localhost web server which is "D:\Apache Group\Apache2\h tdocs\" but
nothing changed...

Hope this shows my problem more clearly..

Thanx!
Ben
Jul 17 '05 #4
duz
cr*********@yah oo.com (Ben) wrote in message news:<d9******* *************** ****@posting.go ogle.com>...
<snip>

I get the following warning:
Warning: Cannot modify header information - headers already sent by
(output started at D:\Apache Group\Apache2\h tdocs\phpfunc.p hp:26) in
D:\Apache Group\Apache2\h tdocs\phpfunc.p hp on line 8


Make the very first line of your main file ob_start() and after you're
done with setting the cookie do a ob_end_flush(). The first command
will cause PHP to buffer the output until the second command is
executed. This also means you don't need to put your cookie function
before the <html> but it is a good idea to execute it as soon as you
can so you don't have to worry about buffering too much output.

Ben
www.dq5studios.com
Jul 17 '05 #5
Ben
dq********@gmai l.com (duz) wrote in message news:<79******* *************** ****@posting.go ogle.com>...
cr*********@yah oo.com (Ben) wrote in message news:<d9******* *************** ****@posting.go ogle.com>...
<snip>

I get the following warning:
Warning: Cannot modify header information - headers already sent by
(output started at D:\Apache Group\Apache2\h tdocs\phpfunc.p hp:26) in
D:\Apache Group\Apache2\h tdocs\phpfunc.p hp on line 8


Make the very first line of your main file ob_start() and after you're
done with setting the cookie do a ob_end_flush(). The first command
will cause PHP to buffer the output until the second command is
executed. This also means you don't need to put your cookie function
before the <html> but it is a good idea to execute it as soon as you
can so you don't have to worry about buffering too much output.


thanx duz,
it's working now...
i did like this in my main file:
<?php
ob_start();
include 'phpfunc.php';
counter();
ob_end_flush()
?>
<html><body></body></html>

Ben
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2934
by: josh dismukes | last post by:
/// here is the code i'm getting a parse error on the last line of the code which /// is </html> any help will be much appreciated. <?php session_start ();
9
2012
by: Philip TAYLOR | last post by:
Configuring a new instance of IIS, I noticed that it allows an HTML-formatted document trailer to be appended to every document served. Unfortunately, on checking its behaviour, I find that it appends the trailer /after/ the closing </HTML> of the document, separated by a blank line. I therefore have a few questions : 1) Assuming HTML 4.01 Transitional, can anything legitimately follow the closing </HTML> tag ?
10
1631
by: Kathy Burke | last post by:
Hi, in trying to discover why my RegisterStartUpScript wouldn't work (I do NOT see it in the HTML source), I looked at the HTML source of a page where I do an XslTransform. First, I get the transform results as expected, beginning with <html> and ending with </html> but then I see the following immediately after that: <HTML> <HEAD>
2
2105
by: taras.di | last post by:
Hi everyone, Is it possible to place javascript outside of <html> tags? I'm trying it on mozilla atm, and it seems to be working, but I was more worried about the older browsers. Cheers Taras
4
3952
by: Mark G. | last post by:
Hello. I am attempting to write a "scraper" to download information from a commercial web site. Oddly enough, they don't want to make this easy for me! Their pages include plenty of Javascript, and more than a few redirects. One that is stumping me is a small page that includes a document object redirect in the <body> tag's onload() event. Like this: <body
1
2248
by: yawnmoth | last post by:
I'm trying to mess around with PHP5's DOM functions and have run into something that confuses me: <?php $dom = new DOMDocument(); $dom->loadHTML('<html></html>'); echo $dom->childNodes->length; ?>
1
2254
by: John | last post by:
Hi var poster="<html><head..... etc .... </html>"; var animal='dog'; The string contains images and text that changes. Originally I wanted to do something like print "<a href=" + poster + ">Choose Poster of a " + animal + "</a>";
3
1904
by: Silmaril | last post by:
hi everyone, i have a question about place of metatags. i've started to seo for active webpage of our client(which is not coded by me) ,but website is very bad coded then i'm a lazy programmer : ) there are so many front pages and but i have a connection include page to use print metatags.. so, what if i put metatags before the <html> tag? is it work for search engines? (especially google and yahoo)
3
3448
by: Arodicus | last post by:
This is bugging me: how do I reference the topmost node (HTML) within a document? I'd like to set a class on it, which specifies various browser/os/versions so that several browser/os/version-specific css bugs may be addressed without coding. eg: <HTML class="_IE _IE7 _Win _IE7Win"> The closest I've come is document.body.parentNode (line 22, below), but this of course requires that my script be executed from within body... I'd prefer to...
0
10523
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10561
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10235
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7766
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5804
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4434
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3995
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3089
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.