简体   繁体   中英

How can I stop myy query in URL is from being lost after loading the page

I have an affiliate program and have a serious problem that I can figure out.

My affiliates have links like this...

 http://example.net/?p=14&ref=delta88

Once the page loads it changes to...

 http://example.net/?p=14

Which totally gets rid of the ref id. I need it to keep the whole URL in the bar in case they hit refresh. Because when you hit refresh it takes the affiliate out of the system and just let's people join without an affiliate.

The way my code works for the pages is this...

That URL goes to an index.php file. In that file it finds all the affiliates information. It then uses an include to show the page. So it's not pointing directly to the page. I need to use the include because I store about 27 pieces of data in strings and I can't put that information in a URL as queries and have it forward to that page.

I added that information because it may be because of the include that's causing it and that will help you better figure out a solution for me.

Use a SESSION, its like a variable that holds for each user, here is a tutorial but works like:

<?php
   session_start();
if(isset($_GET["ref"]){
   $_SESSION["ref"] = $_GET["ref"];
}
?>

Now, in any PHP that open the user, will have that variable set ( $_SESSION["ref"])

you can keep current url in variable , see below used actual_link to hold the current url data.

if($_GET){

    $actual_link = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    //if you want to redirect page on same url just call header with $actual_url
    header('Location: '. $actual_link);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM