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
PHP Redirection Problem
Old 01-28-2009, 01:33 AM PHP Redirection Problem
Novice Talker

Posts: 14
Trades: 0
I'm not an experienced php coder, I just understand basic html. I'm working on a script I found and it's supposed to redirect you to a different website if you come from a specific link or have a referer. If for example: you type in the url to WEBSITEA.COM into the web browser directly there wouldn't be a referer so you would see the content of WEBSITEA.COM and you would not be redirected. If there is a referer, example: you came from a link on another website (http://xxxxxx.com/link.php) then insted of seeing WEBSITEA.COM you will be redirected to another website (WEBSITEB.COM) and you will not see WEBSITEA.COM.

The problem is that the php code on WEBSITEA.COM is not redirecting to WEBSITEB.COM even if there is a referer. I tested by creating a test.html page in a different folder. I checked the headers by using a FF plug-in called, "Tamper Data". When it gets to WEBSITEA.COM where it's supposed to redirect in "Temper Data" it says the referer is /Test/Test.htm so there is a referer. Although it's not redirecting to WEBSITEB.COM

Here's the code:

Code:
  1. <?php
  2. if ( $_SERVER['HTTP_REFERER'] == "http://xxxxxx.com/link.php" ) {
  3. Header ("Location: http://WEBSITE-B.COM"); exit(0);
  4. } else {
  5. }
  6. ?>
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8. <head>

I put in the html tags since this is where the content of WEBSITEA.COM starts if you come to the website with no referer.

I think the problem is with the referer. Since in the above code it's redirecting based on the referer which it's specifying as: http://xxxxxx/link.php. However what I noticed by using, "Tamper Data" is that, the referer is being logged as the site that the link to link.php is placed on. So, if I place a link to http://xxxxx/link.php on Test/Test.htm it's going to specify the referer is Test/Test.htm not http://xxxxx/link.php as in the code above.

I tried modifying the code for testing purposes and changing the server referer line to /Test/Test.htm since this is what it is in "Tamper Data" and it still didn't work.

If I type in the url of WEBSITEA.COM directly into the address bar, I do end up getting the content of WEBSITEA.com so this part is working. It's just not redirecting to WEBSITEB.com if you come through a referer.

If it makes any difference, http://xxxxxx.com/link.php which links to WEBSITEA.COM is always going to be the same link, http://xxxxxx.com/link.php. This link.php is important in determining where the user is redirected. It doesn't matter to me what the referer is since the actual website that links to http://xxxxx.com/link.php will change.


I've been searching for google and trying to set this up for several hours!

Any help would be appreciated,



Thanks!
abcdabcd is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-28-2009, 05:35 AM Re: PHP Redirection Problem
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You appear to be a little confused what the referrer actually is. If it exists of course, because it may not do even from a referrer click.
It will be the address of the page that the link was clicked on.

Quote:
It doesn't matter to me what the referer is since the actual website that links to http://xxxxx.com/link.php will change.
Are you trying to redirect requests for http://xxxxx.com/link.php or user agents referred FROM http://xxxxx.com/link.php?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-28-2009, 05:56 AM Re: PHP Redirection Problem
Novice Talker

Posts: 14
Trades: 0
Quote:
Originally Posted by chrishirst View Post
You appear to be a little confused what the referrer actually is. If it exists of course, because it may not do even from a referrer click.
It will be the address of the page that the link was clicked on.

Are you trying to redirect requests for http://xxxxx.com/link.php or user agents referred FROM http://xxxxx.com/link.php?
Sorry, yes I am kinda confused. Somebody from another forum explained to me how to get the redirect working correctly.

Although the referer is still a problem. As you stated:

"It will be the address of the page that the link was clicked on."

Is it possible make the referer to be of http://xxxxx.com/link.php instead of the address of the page that it was clicked on? Is it possible to change or modify the referer to be anything except for the page that the link was clicked on?


Thanks!
abcdabcd is offline
Reply With Quote
View Public Profile
 
Old 01-28-2009, 06:24 AM Re: PHP Redirection Problem
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Not from where you are.

Modifying (spoofing) the referrer can be done at the client browser/user agent ONLY.

I would think you are looking to use the requested URI (where the link points to). This being the case $_SERVER("REQUEST_URI") is what you are looking for.

NOTE: REQUEST_URI only has the relative path in it (/folder/page.ext). The hostname and protocol are omitted.

also, redirection based on the request would actually be better handled using .htaccess (assuming a Apache server of course)
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-28-2009, 06:35 AM Re: PHP Redirection Problem
jason_alan's Avatar
Super Talker

Posts: 100
Name: Jason
Location: Seattle, WA
Trades: 0
Quote:
Is it possible make the referer to be of http://xxxxx.com/link.php instead of the address of the page that it was clicked on? Is it possible to change or modify the referer to be anything except for the page that the link was clicked on?
Sorry, but it is kinda confusing what to understand what you're trying to accomplish. Can you make your system work by adding a $_GET variable to your referrer links, like link.php?ref=1234 ?

If not, then I guess you must rely on the referrer parameter, though it cannot always be trusted. I am really confused though by what you're trying to accomplish here, based on the quote above.

You can make the referrer be anything you want in the sense of you can choose whether to use or accept the value in the server referrer variable or not. That is what php is all about. Like, if no referrers match what you are looking for you can set the referrer to the default:
PHP Code:
switch($_SERVER['HTTP_REFERER']) {
    case 
'http://webpage.com/blah':
        
$referrer 'blah';
    default: 
        
$referrer 'link.php';

jason_alan is offline
Reply With Quote
View Public Profile
 
Old 01-28-2009, 06:36 AM Re: PHP Redirection Problem
Novice Talker

Posts: 14
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Not from where you are.

Modifying (spoofing) the referrer can be done at the client browser/user agent ONLY.

I would think you are looking to use the requested URI (where the link points to). This being the case $_SERVER("REQUEST_URI") is what you are looking for.

NOTE: REQUEST_URI only has the relative path in it (/folder/page.ext). The hostname and protocol are omitted.

also, redirection based on the request would actually be better handled using .htaccess (assuming a Apache server of course)

Thanks for your reply. I think I understand what you're saying. Since as I stated I'm not really experienced with php. I just want to be clear.

So you are saying to modify the code like this:

Code:
  1. <?php
  2. if ( $_SERVER("REQUEST_URI") == "/link.php" ) {
  3. Header ("Location: http://WEBSITE-B.COM"); exit(0);
  4. } else {
  5. }
  6. ?>
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8. <head>
So even if link.php is in on a different domain and is in the root directory but, in the code above it has /link.php in the above code using Request_Uri. It will make the referer where link.php is located? Instead of where link.php was actually clicked on?

Sorry, if I have it wrong, I'm trying to understand.


Thanks
abcdabcd is offline
Reply With Quote
View Public Profile
 
Old 01-28-2009, 06:43 AM Re: PHP Redirection Problem
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
It will make the referer where link.php is located? Instead of where link.php was actually clicked on?
Nope.

NOTHING on the server can change the referrer. No matter where you redirect the user agent to, the referrer will ALWAYS be the original address of the click.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-28-2009, 06:49 AM Re: PHP Redirection Problem
Novice Talker

Posts: 14
Trades: 0
Quote:
Originally Posted by jason_alan View Post
Sorry, but it is kinda confusing what to understand what you're trying to accomplish. Can you make your system work by adding a $_GET variable to your referrer links, like link.php?ref=1234 ?

If not, then I guess you must rely on the referrer parameter, though it cannot always be trusted. I am really confused though by what you're trying to accomplish here, based on the quote above.

You can make the referrer be anything you want in the sense of you can choose whether to use or accept the value in the server referrer variable or not. That is what php is all about. Like, if no referrers match what you are looking for you can set the referrer to the default:
PHP Code:
switch($_SERVER['HTTP_REFERER']) {
    case 
'http://webpage.com/blah':
        
$referrer 'blah';
    default: 
        
$referrer 'link.php';


Thanks for your reply, let me try to be clearer.

If I place a link on FORUM.COM which links to http://xxxxx.com/link.php then the referer of this final destination will see that the original referer is FORUM.COM.

Is it possible to change the referer so the final destination sees the domain of http://xxxx.com the same site that http://xxxxxx.com/link.php is on? Anything except for the final destination to see that FORUM.COM was the original referer.

So, I would like the referer that the final destination sees to be the link that is actually clicked, NOT WHERE the link was originally clicked at.

Does that make sense?

Let me try one more example

FORUM.COM ----> clicks xxxx.com/link.php (referer is now set to be from forum.com ) -----> redirected to WEBSITEA.COM -----> WEBSITEA.com sees the referer is FORUM.COM. Instead I would like to modify the refer to be the domain of xxxxx.com/link.php not FORUM.COM
abcdabcd is offline
Reply With Quote
View Public Profile
 
Old 01-28-2009, 06:51 AM Re: PHP Redirection Problem
jason_alan's Avatar
Super Talker

Posts: 100
Name: Jason
Location: Seattle, WA
Trades: 0
Yeah, you can't use php to emulate a referrer link click. So, php "header" would not work for you unless you passed the server referrer variable on somehow.
jason_alan is offline
Reply With Quote
View Public Profile
 
Old 01-28-2009, 06:59 AM Re: PHP Redirection Problem
jason_alan's Avatar
Super Talker

Posts: 100
Name: Jason
Location: Seattle, WA
Trades: 0
The referrer is the URL that the link is clicked FROM, and that doesn't seem to be what you are looking for. You are looking for the HOSTNAME that the link is clicked to, correct? You can check for $_SERVER['HTTP_HOST'] to see the domain name or IP address being requested. Still not sure what you're trying to achieve, but there's got to be a better way.
jason_alan is offline
Reply With Quote
View Public Profile
 
Old 01-28-2009, 07:02 AM Re: PHP Redirection Problem
jason_alan's Avatar
Super Talker

Posts: 100
Name: Jason
Location: Seattle, WA
Trades: 0
if you have a php setup on your computer, you can use this script to discover what the $_SERVER global array contains when you try to load a page, that you can use in your scripts.
PHP Code:
<?php
echo '<pre>';
print_r($_SERVER);
?>
jason_alan is offline
Reply With Quote
View Public Profile
 
Old 01-28-2009, 07:42 AM Re: PHP Redirection Problem
Novice Talker

Posts: 14
Trades: 0
Quote:
Originally Posted by jason_alan View Post
The referrer is the URL that the link is clicked FROM, and that doesn't seem to be what you are looking for. You are looking for the HOSTNAME that the link is clicked to, correct? You can check for $_SERVER['HTTP_HOST'] to see the domain name or IP address being requested. Still not sure what you're trying to achieve, but there's got to be a better way.
I am personally not looking for the hostname, I already know what it is. I just want the hostname of the link that is clicked to, to be the referer that the final destination (website) sees as the referer instead of the URL that the link is clicked FROM.

although according to the previous posts, it doesn't seem like it's going to be possible.



Thanks for the help,
abcdabcd is offline
Reply With Quote
View Public Profile
 
Old 01-28-2009, 08:07 AM Re: PHP Redirection Problem
jason_alan's Avatar
Super Talker

Posts: 100
Name: Jason
Location: Seattle, WA
Trades: 0
Hmm.. All I can think is to refer you to the HTTP_REFERRER variable in your $_SERVER array. Otherwise I'm not sure what to tell you
jason_alan is offline
Reply With Quote
View Public Profile
 
Old 01-28-2009, 08:18 AM Re: PHP Redirection Problem
Novice Talker

Posts: 14
Trades: 0
Quote:
Originally Posted by jason_alan View Post
Hmm.. All I can think is to refer you to the HTTP_REFERRER variable in your $_SERVER array. Otherwise I'm not sure what to tell you
Do you mean like this:

Code:
<?php
if($_SERVER['HTTP_REFERER'])
{
header('Location: http://www.xxxxx.com');
exit();
}
?>
This is what I'm doing currently from what I was advised on another forum. Using this at least the redirect works but, the referer is still a problem.

In your method you advised:

Code:
switch($_SERVER['HTTP_REFERER']) {
    case 'http://webpage.com/blah':
        $referrer = 'blah';
    default: 
        $referrer = 'link.php';
}  

So I should just replace the code I was advised with your code just like above and see if that works? I'll try it out and see what results I get.


Thanks
abcdabcd is offline
Reply With Quote
View Public Profile
 
Old 01-28-2009, 08:22 AM Re: PHP Redirection Problem
Novice Talker

Posts: 14
Trades: 0
actually I'm kinda confused as to how I can implement your code. In the script I just pasted it has an if statement since the code on this website is determining if the website visitor has a referer or not. If it has a referer they go to a different site if they don't have a referer (ie: typed url into browser directly) they stay on the same site.

So in your code instead of if you have switch, I don't know if your code works like mine does if so, where I would input the link to redirect to if there is a referer.



Thanks!

Last edited by abcdabcd; 01-28-2009 at 08:25 AM..
abcdabcd is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP Redirection Problem
 

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.59900 seconds with 12 queries