Results 1 to 4 of 4
  1. #1
    Full Member
    Join Date
    January 17th, 2005
    header link being blocked/truncated by '&'
    I am trying to redirect a link using the following:


    $SaleURL = purchase.php?link=;

    print "<a href=\"" . $SaleURL ."\">Click Here!</a>';


    $link = $_GET['link'];
    header ('location: " . $link);

    Most of the ugly, long URLs transfer through Header just fine - ones of the type shown are sent correctly (according to the access.log file from Apache) but are truncated (in Header???) just before the first '&' sign in the ones that include a combining '&' sign.

    IE - the link being sent from the header function is of the form:

    $link = purchase.php?link=

    Any thoughts what I can do to fix this?

    Thanks - Charles

  2. #2
    Roll Tide mobilebadboy's Avatar
    Join Date
    January 18th, 2005
    Mobile, Alabama
    One way is to rewrite the link before you send it out, using str_replace. Just replace the & with &amp; ... It will still work, the &amp; will still be interpreted as &, but & is an operator in PHP so it can get confusing when written within other code. There may be another way, but that will work.

    PHP Code:
    $SaleURL purchase.php?link=;
    $SaleURL str_replace("&""&amp;" $SaleURL);
    "<a href=\"" $SaleURL ."\">Click Here!</a>'; 

    Shawn Kerr (.com) | Disney World | SEC Football

  3. #3
    Join Date
    February 5th, 2007
    Your method doesn't work because everything after ? (query string) is automatically parsed and every part after & gets its own variable:

    link= became:
    $_GET['link'] = '';
    $_GET['offerid'] = '101744.23405';
    $_GET['type'] = 15;

    Below one possible solution.


    $SaleURL = 'purchase.php?' . urlencode('');

    notice that there is no "link=" part in $SaleURL


    $link = $_SERVER['QUERY_STRING'];
    if(strpos($link, '')===0) header ('Location: ' . $link);

  4. #4
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Try this:
    $query_string = $_SERVER['QUERY_STRING'];
    preg_match("/\&link\=(.+)$/", $query_string, $matches);
    $link = $matches[1];
    It does a regular expression on the entire query string. You just need to make sure the link is the last part of the URL. It basically grabs everything after &link= and stores it in $link.

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  5. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. How to link the header to the front page?
    By Decorative Ceiling Tiles in forum Programming / Datafeeds / Tools
    Replies: 4
    Last Post: September 3rd, 2010, 01:49 PM
  2. A Sign of the Times - CJ Link Blocked
    By John Powell in forum Commission Junction - CJ
    Replies: 29
    Last Post: January 14th, 2007, 09:15 PM
  3. Truncated Descriptions...
    By mobilebadboy in forum ShareASale - SAS
    Replies: 3
    Last Post: November 19th, 2004, 03:54 PM

Posting Permissions

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