Jump to content

Recommended Posts

I am working on a function for a site that I am working. The function itself is working fine minus one element. What the concept is, is a user clicks on a link to allow this function to go to its corresponding loading page, runs it script, and then sends the user back to where they were since the ability to use the function is spread out through out the site there is no static means per say of doing it. I have been attempting to use

 

$_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];

 

To catch the last URL prior to running the function, but I keep getting stuck in an endless loop cause the function looks for a specfic var in the URL to activate and run. So using $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']; catches that particular var as well so I need a way to trim it out if its in the url but only after the function runs. the var is "theme=xxxxxxx" xxxxxx being anything from 3-16 char long. I have made it so that it appends to the end of the URI everytime however. So anyone any suggestions or ideas as to how I can do this?

Link to comment
https://forums.phpfreaks.com/topic/158121-solved-trim-a-url-if/
Share on other sites

Thank you..

 

I ended up playing a bit and with a little searching combined with the playing I came to this..

 

function remove_querystring_var($url, $key) {
    $url = preg_replace('/(.*)(\?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
    $url = substr($url, 0, -1);
    return ($url);
}
$backlink2use = $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];
$backlink2use = remove_querystring_var($backlink2use, "theme");

Link to comment
https://forums.phpfreaks.com/topic/158121-solved-trim-a-url-if/#findComment-834057
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.