Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2012-02-29, 03:14 AM   #1
A.J. Angel
And Lord, we are especially thankful for nuclear power, the cleanest, safest
energy source there is. Except for solar, which is just a pipe dream
 
Join Date: Sep 2008
Posts: 229
PHP Referrer & Display Help

Hello,

I am currently using the following code below to display two different codes depending on referrers. It came to my attention that if the page is visited from a direct url or a bookmark for example, the include is not working. It only works if the page is visited from "somewhere".

As such, I wish to ask if someone may be able to "fix" the code. Basically, I wish to display the first code if the visitor comes from domain.com otherwise, the include is displayed no matter where else they come from. Thank you in advance.

PHP Code:
      if(isset($_SERVER['HTTP_REFERER'])) {
          
$referrer $_SERVER['HTTP_REFERER'];
          if(
stristr($referrer'domain.com')) {
               echo 
'<INSERT CODE>';
          } else {
               include 
$_SERVER['DOCUMENT_ROOT'].("/path/to/file.html");
          }
     } 

Last edited by A.J. Angel; 2012-02-29 at 03:22 AM..
A.J. Angel is offline   Reply With Quote
Old 2012-02-29, 11:25 AM   #2
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
On a bookmark or typein, HTTP_REFERER won't be set - and your condition skips your includes in that case.

Code:
          $referrer = $_SERVER['HTTP_REFERER']; 
          if( (stristr($referrer, 'domain.com')) || ($referrer=="") ) { 
               echo '<INSERT CODE>'; 
          } else { 
               include $_SERVER['DOCUMENT_ROOT'].("/path/to/file.html"); 
          }
Disclaimer: yes, there are better ways to write that at the expense of the code being less easily modified.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
Old 2012-02-29, 06:22 PM   #3
A.J. Angel
And Lord, we are especially thankful for nuclear power, the cleanest, safest
energy source there is. Except for solar, which is just a pipe dream
 
Join Date: Sep 2008
Posts: 229
Quote:
Originally Posted by cd34 View Post
On a bookmark or typein, HTTP_REFERER won't be set - and your condition skips your includes in that case.

Code:
          $referrer = $_SERVER['HTTP_REFERER']; 
          if( (stristr($referrer, 'domain.com')) || ($referrer=="") ) { 
               echo '<INSERT CODE>'; 
          } else { 
               include $_SERVER['DOCUMENT_ROOT'].("/path/to/file.html"); 
          }
Disclaimer: yes, there are better ways to write that at the expense of the code being less easily modified.
Good observation. What does the code below mean?

PHP Code:
|| ($referrer=="") ) 
Another helper directed me to simply delete the first condition without adding anything. I would appreciate any indications in order to understand things better. Thank you.
A.J. Angel is offline   Reply With Quote
Old 2012-02-29, 10:29 PM   #4
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
if you just delete the first condition, if the referrer is empty, it would do your include. My guess at your intention was to include the local code if it was a typein/bookmark or local site referrer, and include the /path/to/file.html if it was a remote referrer.

|| ($referrer=="") )

says: or, the referrer is empty

if you want to include the INSERT CODE for local hits + bookmarks/typeins, you want to use the || ($referrer=="") ) version. If you want only want to display INSERT CODE for local hits, and bookmarks/typeins/remote referrers get the /path/to/file.html, then just removing the isset() condition would do that.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
Old 2012-02-29, 10:39 PM   #5
A.J. Angel
And Lord, we are especially thankful for nuclear power, the cleanest, safest
energy source there is. Except for solar, which is just a pipe dream
 
Join Date: Sep 2008
Posts: 229
Actually, my intention is the contrary, intending to display the <INSERT CODE> if the visitor comes from a particular domains but in case the visitor does not come from that domain, they would be instead be displayed the include to /path/to/file.html.
A.J. Angel is offline   Reply With Quote
Reply


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

Forum Jump


All times are GMT -4. The time now is 01:06 PM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc