Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2010
    Posts
    118
    Thanks
    6
    Thanked 0 Times in 0 Posts

    How do you change the URl referrer?

    It's long explanation as to why ... so here is the short version of the "what" needs to be acheived:

    I have traffic coming in from various sources that are constantly changing. I run them all through one page:

    e.g. www.mysite.com/js/out.php

    which spits the visitors out to a varied selection of pages based on certain parameters using:

    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: $locationtosend" );

    once the right page for them has been found. What I need is for /js/out.php to also change the referring URl to being itself. That doesn't seem to be achievable using a PHP 301 redirect?

    I need the $_SERVER['HTTP_REFERER'] to be /js/out.php for every landing page. Right now, it is the original referring site.

    Any ideas?

    Thanks
    Mike

  • #2
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    Look into using .htaccess or web.config, depending on your server, in conjunction with your PHP script

    http://www.addedbytes.com/articles/f...for-beginners/

  • #3
    Regular Coder
    Join Date
    Apr 2010
    Posts
    118
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Someone has suggested:

    <script type="text/javascript">document.location.href='http://www.mysite.com/';</script>
    <script type="text/javascript">window.location.href='http://www.mysite.com/';</script>
    I tried it and it seemed to work. It made the referal URl /js/out.php which is what I wanted.

    The fact this was so easy to sort, has me worried! What am I missing? What's wrong with this javascript solution? Only a handful of people won't have javascript turned on. And the two scripts cover most browsers?

  • #4
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    "Only a handful of people won't have javascript turned on."

    That's the reason why people don't use javascript unless absolutely necessary. What will you do for those people? Those people usually are attempting something malicious or have a mind for security and disable it

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,471
    Thanks
    0
    Thanked 634 Times in 624 Posts
    Quote Originally Posted by instaunt View Post
    Someone has suggested:
    Both of those are exactly the same thing. You don't need to specify anything in front of location at all.

    Quote Originally Posted by instaunt View Post
    Only a handful of people won't have javascript turned on.
    That handful (which is usually between 2 and 10% for most sites) will include 100% of those trying to bypass whatever it is you are attempting to achieve. It will also include a lot of disabled people some of whom have been known to sue web sites that discriminate against them by requiring JavaScript.

    Also JavaScript can be easily turned on and off in the browser so as soon as your script tries to do something that people don't like the percentage with JavaScript off for your site will soon grow to over 50%.

    Even without all those issues and assuming that your site has the smallest percentage of visitors with JavaScript off - do you really want those people telling all their friends that your site is broken and to go to some other site that does the same thing and actually works.


    The other thing to remember is that it is easy for anyone to change the referrer header if you give them a reason to do so. The developer tools in most browsers allow access to change it and many firewalls simply blank it out for privacy reasons.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •