1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP w/ Redirect w/ Header Question

Discussion in 'Cloaking and Content Generators' started by UberNewb, May 20, 2012.

  1. UberNewb

    UberNewb Newbie

    Joined:
    May 16, 2011
    Messages:
    24
    Likes Received:
    1
    Occupation:
    IT Tech
    Location:
    Maryland
    I'm trying to make a dynamic PHP redirect script, i've found some code but not completely helpful it gives me a forbidden error.

    <?php
    $pid = (varchar)($_GET['pid']);
    header('Location: $pid');
    ?>

    is the code in my php file i am passing $pid in the link address.

    I cannot use javascript as some peeps disable this. any ideas?

    TY
     
  2. bouquet

    bouquet Regular Member

    Joined:
    Mar 22, 2012
    Messages:
    388
    Likes Received:
    148
    Occupation:
    BUM!
    Location:
    darkside of the moon
    could use the htaccess file

    that would redirect the domain to your new domain or do you just want to redirect one page or a folder?
     
  3. bouquet

    bouquet Regular Member

    Joined:
    Mar 22, 2012
    Messages:
    388
    Likes Received:
    148
    Occupation:
    BUM!
    Location:
    darkside of the moon
    if you just wanted to redirect a page using php use

     
  4. Sprouts

    Sprouts Regular Member

    Joined:
    Mar 20, 2010
    Messages:
    461
    Likes Received:
    324
    <?php
    $pid = (varchar)($_GET['pid']);
    $url = "http://www.mysite.com?page=" . $pid;
    header('Location: $url');
    ?>

    Try the above assuming your page structure is: http://www.mysite.com?page=2
    Change according to page structure...
     
    • Thanks Thanks x 1
  5. bouquet

    bouquet Regular Member

    Joined:
    Mar 22, 2012
    Messages:
    388
    Likes Received:
    148
    Occupation:
    BUM!
    Location:
    darkside of the moon
    Sorry just re-read your original post, need beer...!!!

    If you are getting a variable with $pid then you need to append it to a domain/page so something like

    Or are you saying that $pid contains the url you wish to redirect to?
     
  6. UberNewb

    UberNewb Newbie

    Joined:
    May 16, 2011
    Messages:
    24
    Likes Received:
    1
    Occupation:
    IT Tech
    Location:
    Maryland
    $pid contains the URL i would like to redirect to ;) ty all for quick responses, gonna try some of these and see what happens/make changes as appropriate
     
  7. bouquet

    bouquet Regular Member

    Joined:
    Mar 22, 2012
    Messages:
    388
    Likes Received:
    148
    Occupation:
    BUM!
    Location:
    darkside of the moon
    I would echo out what $pid contains first then you can work out what you need, as it maybe missing something?
     
  8. UberNewb

    UberNewb Newbie

    Joined:
    May 16, 2011
    Messages:
    24
    Likes Received:
    1
    Occupation:
    IT Tech
    Location:
    Maryland
    actually here is another option, i have the URL already stored in a variable on the previous page..

    $product_link , they are clicking on a picture that is a hyperlink, but i am trying to cloak it to some level, when they click the picture link, can it call a php script to forward them?

    TY all
     
  9. bouquet

    bouquet Regular Member

    Joined:
    Mar 22, 2012
    Messages:
    388
    Likes Received:
    148
    Occupation:
    BUM!
    Location:
    darkside of the moon
    yes I do something similar on one of my sites, I have a go.php file which the image is linked to when a user clicks the image it loads the file which then stores some info in a db then redirects the user somewhere else.
     
  10. UberNewb

    UberNewb Newbie

    Joined:
    May 16, 2011
    Messages:
    24
    Likes Received:
    1
    Occupation:
    IT Tech
    Location:
    Maryland
    Ok, after a lil bit of research I have found that I am getting the error because the host i'm using has a setting in ModSecurity that needs to be changed. Once that is done if anyone is interested I'll post correctly functioning code.
     
  11. bouquet

    bouquet Regular Member

    Joined:
    Mar 22, 2012
    Messages:
    388
    Likes Received:
    148
    Occupation:
    BUM!
    Location:
    darkside of the moon
    i'll be intersted mate, always interested in seeing how others code what i'm doing too.
     
  12. UberNewb

    UberNewb Newbie

    Joined:
    May 16, 2011
    Messages:
    24
    Likes Received:
    1
    Occupation:
    IT Tech
    Location:
    Maryland
    below works, problem was with modsecurity as stated above.
    <?php
    $link=$file;
    header ("Location: $link");
    exit();
    ?>
     
  13. bouquet

    bouquet Regular Member

    Joined:
    Mar 22, 2012
    Messages:
    388
    Likes Received:
    148
    Occupation:
    BUM!
    Location:
    darkside of the moon
    cool, i doubt you need the exit statement as you are redirecting on the line above but hey thats just being picky....!!!!! LOL
     
  14. UberNewb

    UberNewb Newbie

    Joined:
    May 16, 2011
    Messages:
    24
    Likes Received:
    1
    Occupation:
    IT Tech
    Location:
    Maryland
    Yes, my thoughts as well, but every reference I can find recommends doing it anyway as a just 'in case' lol, the other thing I did find was that since these are affiliate links and contain gargantuan amounts of ampersands was they needed to be replaced with %26. I just did a replace all w/ excel and re-imported my table and from there it worked. will have to write a routine to fix this though as I can see it causing a lot of problems when i scale this to other sites. also any opinions on if this hides the link from google? hrm
     
  15. wangzhengkun

    wangzhengkun Newbie

    Joined:
    May 22, 2012
    Messages:
    1
    Likes Received:
    1
    hi friend,thanks for your post.
     
    • Thanks Thanks x 1
  16. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    You only need to replace the ampersands? You can just loop through the table and use str_replace to replace the ampersands with %26.

    PHP:
    $getLinks mysql_query("SELECT `id`,`link` FROM `links` WHERE `link` LIKE '%&%'");
    while (
    $linksArr mysql_fetch_array($getLinks)) {
       
    $linkId $linksArr['id'];
       
    $newLink str_replace("&""%26"$linksArr['link']);
       
    mysql_query("UPDATE `links` SET `link`='$newLink' WHERE `id`='$linkId'");
    }
    mysql_close();
    Something like that. You can also do that when retrieving links for forwarding or when inserting links from your control panel if you have one.
     
    • Thanks Thanks x 1
  17. UberNewb

    UberNewb Newbie

    Joined:
    May 16, 2011
    Messages:
    24
    Likes Received:
    1
    Occupation:
    IT Tech
    Location:
    Maryland
    Yeah my final result was actually eliminating the whole URL and just passing the product ID, wallah!

    Yes, I could have done strreplace but im a very big noob when it comes to php, mostly learning from what I can find from other websites. TY!