Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How do I properly insert "include" line?
Old 06-27-2011, 07:20 PM How do I properly insert "include" line?
celife's Avatar
Average Talker

Posts: 26
Name: Chris
Trades: 0
Hi,

I was told by statcounter that to use their code on a php redirect page I should create a page with statcounter code on it such as statcounter.html then add it to my page. However, I don't know where to add it and it may be several days before I get a reply from them. So I'm curious if my php code currently looks like this:

<?php
header( 'Location: http://www.example.com' ) ;
?>

would the "include" line then be added so it looks like this?:

<?php
header( 'Location: http://www.example.com' ) ;
include 'statcounter.com.html';
?>

Or would I add it elsewhere? I want to make sure the redirect still works, and the click is tracked as well.

Thanks,
Chris
__________________
Compare Major Psychic Sites -
Please login or register to view this content. Registration is FREE
celife is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-27-2011, 07:25 PM Re: How do I properly insert "include" line?
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
The include() and require() functions basically copies the code/text from the given address and pastes it where the include was made (look at php.net). I dont know how this statcounter is suppose to be used but I can guarantee that you should not include anything after your redirect. Since the user will be redirected from the page any code after the redirect will not be run.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 06-27-2011, 08:00 PM Re: How do I properly insert "include" line?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by lizciz View Post
I can guarantee that you should not include anything after your redirect. Since the user will be redirected from the page any code after the redirect will not be run.
This isn't the case. The script isn't halted by calling header; it will finish executing even if you redirect the user.

What you shouldn't do after calling header is send any output to the user. If the file you're including is going to send output (and I'm guessing from the .html extension it is) then it won't have any affect.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 06-27-2011 at 08:41 PM..
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-28-2011, 04:21 AM Re: How do I properly insert "include" line?
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Quote:
Originally Posted by NullPointer View Post
This isn't the case. The script isn't halted by calling header; it will finish executing even if you redirect the user.

What you shouldn't do after calling header is send any output to the user. If the file you're including is going to send output (and I'm guessing from the .html extension it is) then it won't have any affect.
Oh, I didn't know that, thanks!
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 06-28-2011, 05:22 AM Re: How do I properly insert "include" line?
celife's Avatar
Average Talker

Posts: 26
Name: Chris
Trades: 0
Thanks for the input, folks.

I was finding that:

<?php
header( 'Location: http://www.example.com' ) ;
include 'statcounter.com.html';
?>

(end of paste)

wasn't working. The redirect still worked, but clicks were not measured. I changed the code (on a whim) to:

<?php
header( 'Location: http://www.example.com' ) ;
?>
include 'statcounter.com.html';

(end of paste)

and now it appears to be working. Please let me know if there's something wrong with this format but at this point it appears to be both tracking clicks and properly redirecting.
__________________
Compare Major Psychic Sites -
Please login or register to view this content. Registration is FREE
celife is offline
Reply With Quote
View Public Profile
 
Old 06-28-2011, 05:26 AM Re: How do I properly insert "include" line?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by celife View Post
PHP Code:
<?php
header
'Location: http://www.example.com' ) ;
?>
include 'statcounter.com.html';
(end of paste)

and now it appears to be working. Please let me know if there's something wrong with this format but at this point it appears to be both tracking clicks and properly redirecting.
If the call to include is outside of the PHP tags then it isn't being parsed; the literal string "include 'statcounter.com.html';" would be output to the browser if it weren't for the fact it is after the redirect.

I'm not sure how the click tracking is working, but based on the code you posted that file is not being included properly.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-28-2011, 05:32 AM Re: How do I properly insert "include" line?
celife's Avatar
Average Talker

Posts: 26
Name: Chris
Trades: 0
Thanks for your feedback. I'm not sure if this makes a difference but the only content on the .html page is invisible statcounter code. I don't know anything about .php coding, but so far the most recent format I listed does seem to do the trick. My only concern is that all of the affiliate code link in the redirect may not be passed along in this format.
__________________
Compare Major Psychic Sites -
Please login or register to view this content. Registration is FREE
celife is offline
Reply With Quote
View Public Profile
 
Old 06-28-2011, 05:40 AM Re: How do I properly insert "include" line?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by celife View Post
I'm not sure if this makes a difference but the only content on the .html page is invisible statcounter code.
It doesn't make a difference, but based on the code you posted, that code isn't being sent to the browser. The include line is PHP code so it should be inside the PHP tags.

I should have pointed this out before, but you can't have any output prior to calling header(), and as I already pointed out, any output after a redirect has no affect. In other words you shouldn't have any output before or after calling header() in this case.

In order to have the code in the statcounter file be sent to the browser and have the page redirect you would need to use a javascript redirect.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-28-2011, 05:51 AM Re: How do I properly insert "include" line?
celife's Avatar
Average Talker

Posts: 26
Name: Chris
Trades: 0
Thanks Nullpointer
__________________
Compare Major Psychic Sites -
Please login or register to view this content. Registration is FREE
celife is offline
Reply With Quote
View Public Profile
 
Old 06-28-2011, 06:02 AM Re: How do I properly insert "include" line?
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Just to echo the point above about scripts continuing to execute after a header call - I did comment on this on several posts but nobody seemed to care - and there will have been some very dodgy results and puzzled php newbies!

To make sure you get what you think you're getting, do an exit(); immediately after a header relocation.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How do I properly insert "include" line?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31266 seconds with 12 queries