1. This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
    For information on cookies and how you can disable them visit our Cookie Usage page.
    Dismiss Notice

PHP PHP Refer

Discussion in 'Web Development' started by vareside, Jun 27, 2008.

  1. vareside

    vareside New Member

    Hi folks,
    I need a script which enables me to refer users to a specific websites according to a parameter.

    Example:
    URL of page with script: www.abc.de/page.php?out=vareside.com
    Refered to URL: www.vareside.com

    How to do this? Tutorials, links, snippets or hints are welcome.
     
  2. ishkey

    ishkey Moderator, Logos, Sports Crests Staff Member Verified Member

    Better to use $_SERVER["HTTP_REFERER"] to know the referer URL. If the user followed a link to the current page then the referer is theURL that the user has come to the current page from. If they typed in the URL directly or came from their bookmarks then the referer is generally empty. PHP makes the referer automatically available in the variable: $HTTP_REFERER - the url the client just came from. The referer is actually stored in an environment variable which you canget using getenv():

    A basic script
    <?php
    if (!isset($_SESSION['referrer'])) $_SESSION['referrer']=$_SERVER['HTTP_REFERRER'];
    if((strpos($a, 'www.foo.com') > -1) || ($a == ''))
    {
    // good referer
    }

    ?>
     
  3. vareside

    vareside New Member

    Thanks, but isn't the following script much better?

    <?
    foreach ($_GET as $key => $value) {
    $site .= $key."=".$value."&";
    }
    $site = substr($site, 4, -1);
    intact
    ?>
    <?php
    header("location:$site");
    ?>
     
  4. ishkey

    ishkey Moderator, Logos, Sports Crests Staff Member Verified Member

    I have been looking at this one and it would depend upond your version of php.
    the foreach construct in php 4 gives an easy way to iterate over arrays. foreach works only on arrays, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable. Unless the array is referenced, foreach operates on a copy of the specified array and not the array itself. foreach has some side effects on the array pointer. Don't rely on the array pointer during or after the foreach without resetting it.
    Reference of a $value and the last array element remain even after the foreach loop. It is recommended to destroy it by unset(). You will get extremely hard-to-find bugs if you leave out the unset().

    $_GET['id'] In PHP 4.2.0 and later, the default value for the PHP directive register globals is off. To get DOCUMENT_ROOT you'll use $_SERVER['DOCUMENT_ROOT']

    substr Returns the portion of string specified by the start and length parameters.
    substr($site, 4, -1); If start is negative, the returned string will start at the start 'th character from the end of string. If start is non-negative, the returned string will start at the start 'th position in string , counting from zero. so I'm not understanding the 4.
     
  5. vareside

    vareside New Member

    Thanks.

    Max
     
  6. ishkey

    ishkey Moderator, Logos, Sports Crests Staff Member Verified Member

    Here is a Java IP (InetAddress) Locator from SourceForge
    Java and ColdFusion libraries to lookup country code and language from IP address. It uses a local copy of the WHOIS database to perform fast, accurate lookups of country codes. Useful for log analysis, internationalization, geolocation, etc..
    http://sourceforge.net/projects/javainetlocator/

    How about taking the variables from the script and passing them to a php file to process the reffer site. Most people have java turned on, you would only miss out on private servers. And why not set a cookie so when they return you can process them.
     
  7. vareside

    vareside New Member

    Thank you very much.
     
  8. DanielXP

    DanielXP New Member

    PHP:
    <?
    header("Location: " $_GET[out])
    ?>
     
  9. pezboy45

    pezboy45 Mod/Design & Coder [Pro]

    where do you define which link corresponds to which outside link?