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


    "Index.php"

    $SaleURL = purchase.php?link=http://click.linksynergy.com/fs-bin/click?id=xxxxxxxx&offerid=101744.23405&type=15&subid=0;

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



    "purchase.php"

    $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=http://click.linksynergy.com/fs-bin/click?id=xxxxxxxxxxx

    Any thoughts what I can do to fix this?

    Thanks - Charles

  2. #2
    Roll Tide mobilebadboy's Avatar
    Join Date
    January 18th, 2005
    Location
    Mobile, Alabama
    Posts
    1,220
    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=http://click.linksynergy.com/fs-bin/click?id=xxxxxxxx&offerid=101744.23405&type=15&subid=0;
    $SaleURL str_replace("&""&amp;" $SaleURL);
    print 
    "<a href=\"" $SaleURL ."\">Click Here!</a>'; 

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

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

    link=http://click.linksynergy.com/fs-bin/click?id=xxxxxxxx&offerid=101744.23405&type=15&subid=0 became:
    $_GET['link'] = 'http://click.linksynergy.com/fs-bin/click?id=xxxxxxxx';
    $_GET['offerid'] = '101744.23405';
    $_GET['type'] = 15;
    etc.

    Below one possible solution.

    Index.php:

    $SaleURL = 'purchase.php?' . urlencode('http://click.linksynergy.com/fs-bin/click?id=xxxxxxxx&offerid=101744.23405&type=15&subid=0');

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

    purchase.php:

    $link = $_SERVER['QUERY_STRING'];
    if(strpos($link, 'http://click.linksynergy.com/fs-bin/click?')===0) header ('Location: ' . $link);

  4. #4
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    Try this:
    Code:
    $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, 02: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, 10:15 PM
  3. Truncated Descriptions...
    By mobilebadboy in forum ShareASale - SAS
    Replies: 3
    Last Post: November 19th, 2004, 04: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
  •