How to cut a URL variable

I have url.LoginID and I would like to remove it from the address bar when the user clicks on the login link. It must be a bookmark, it cannot be represented in the form.

Q: How to remove? LoginID of Index.cfm? LoginID = XYZ & AssignmentID = 123

This is probably something like:

<cflocation url="#cgi.SCRIPT_NAME#?#cgi.QUERY_STRING#" addtoken="no">
+3
source share
5 answers

You seem to be on the right track.

If loginID is the only thing in the query string, you can simply copy to the landing page without the query string.

If there is other data in the query string, you can do something like this:

<cfset q = reReplaceNoCase(cgi.query_string, "LOGINID=[^&]+&?", "")>
<cflocation url="#cgi.SCRIPT_NAME#?#q#">

This substantially removes the loginid and all until a line or the next URL variable is declared.

+19
source

, UDF, - CFLIB: queryStringDeleteVar

<cflocation 
    url="#cgi.SCRIPT_NAME#?#queryStringDeleteVar("LoginID",cgi.QUERY_STRING)#" 
    addtoken="no"
>

CGI.QUERY_STRING arg,

<cflocation 
    url="#cgi.SCRIPT_NAME#?#queryStringDeleteVar("LoginID")#" 
    addtoken="no"
>

queryStringDeleteVar:

<cfscript>
/**
 * Deletes a var from a query string.
 * Idea for multiple args from Michael Stephenson (michael.stephenson@adtran.com)
 * 
 * @param variable      A variable, or a list of variables, to delete from the query string. 
 * @param qs      Query string to modify. Defaults to CGI.QUERY_STRING. 
 * @return Returns a string. 
 * @author Nathan Dintenfass (michael.stephenson@adtran.comnathan@changemedia.com) 
 * @version 1.1, February 24, 2002 
 */
function queryStringDeleteVar(variable){
    //var to hold the final string
    var string = "";
    //vars for use in the loop, so we don't have to evaluate lists and arrays more than once
    var ii = 1;
    var thisVar = "";
    var thisIndex = "";
    var array = "";
    //if there is a second argument, use that as the query string, otherwise default to cgi.query_string
    var qs = cgi.query_string;
    if(arrayLen(arguments) GT 1)
        qs = arguments[2];
    //put the query string into an array for easier looping
    array = listToArray(qs,"&");        
    //now, loop over the array and rebuild the string
    for(ii = 1; ii lte arrayLen(array); ii = ii + 1){
        thisIndex = array[ii];
        thisVar = listFirst(thisIndex,"=");
        //if this is the var, edit it to the value, otherwise, just append
        if(not listFind(variable,thisVar))
            string = listAppend(string,thisIndex,"&");
    }
    //return the string
    return string;
}
</cfscript>
+4

, , :

<cfset newParams = "" />

<cfloop list="#cgi.query_string#" delimiters="&" index="i">
    <cfif listFirst(i, "=") neq "loginID">
        <cfset newParams = listAppend(newParams, i, "&") />
    </cfif>
</cfloop>


<cflocation url="#cgi.script_name#?#newParams#" addtoken="no">

, !

+3

, ?, URL- , :

QUERY_STRING = ReReplaceNoCase(cgi.QUERY_STRING, "LoginID=.+\&", "");

, , LoginID URL- , . .

Edit: Ben regex is better because my version is so simple that it will "eat" all the pairs key=valueuntil the last.

+2
source

Insert the famous quote from the Zawinski 2 cycle and decide otherwise:

<cfset copy = duplicate(url)>
<cfset structDelete(copy, "loginid")>
<cfset entries = []>
<cfloop collection="#copy#" item="key">
    <cfset arrayAppend(entries, "#key#=#copy[key]#")>
</cfloop>
<cfoutput>#arrayToList(entries, "&")#</cfoutput>
+1
source

Source: https://habr.com/ru/post/1785631/


All Articles