Jump to content

Check if URL contains some value


JelleG

Recommended Posts

I want to check if my currenty URL contains some value. Therefore I use the following code, but that does not work.

 

{if $smarty.server.HTTP_REFERER|strstr:'domain=transfer&sld='}

 

The full URL;

 

https://example.com/cart.php?a=add&domain=transfer&sld=value&tld=.com

 

What am I missing?

Link to comment
Share on other sites

they'd be a few ways to do it - depending on where you are wanting to add the code...

 

the best way would likely be to use GET, so the following should work...

 

{if $smarty.get.domain eq 'transfer'}

that will effectively check for 'domain=transfer' in the URL... but you could string multiple queries together if you wanted to be more specific...

 

{if $smarty.get.domain eq 'transfer' and $smarty.get.sld eq 'value'}

or you could see if an existing variable contains your string...

 

{if $currentpagelinkback|strstr:'domain=transfer&sld='}

... but using GET should be your first choice where possible. :idea:

Link to comment
Share on other sites

they'd be a few ways to do it - depending on where you are wanting to add the code...

 

the best way would likely be to use GET, so the following should work...

 

{if $smarty.get.domain eq 'transfer'}

that will effectively check for 'domain=transfer' in the URL... but you could string multiple queries together if you wanted to be more specific...

 

{if $smarty.get.domain eq 'transfer' and $smarty.get.sld eq 'value'}

 

Amazing, thanks a lot!!

 

But I want to check if the URL contains 'transfer' and also if there is a 'sld' with some value.

Because the sld is dynamic, the second rule does not work, because the 'value' is dynamic.

 

Is this also possible using the GET?

Link to comment
Share on other sites

Amazing, thanks a lot!!

But I want to check if the URL contains 'transfer' and also if there is a 'sld' with some value.

Because the sld is dynamic, the second rule does not work, because the 'value' is dynamic.

Is this also possible using the GET?

just check to see if the variable exists...

 

{if $smarty.get.domain eq 'transfer' and $smarty.get.sld}

so using your URL above, the if statement should be true and work... if you change the URL to 'cart.php?a=add&domain=transfer&tld=.com', then it should fail. :idea:

Link to comment
Share on other sites

just check to see if the variable exists...

 

{if $smarty.get.domain eq 'transfer' and $smarty.get.sld}

so using your URL above, the if statement should be true and work... if you change the URL to 'cart.php?a=add&domain=transfer&tld=.com', then it should fail. :idea:

 

Thanks that works well!

The only thing is, I want to use that line also in the domainoptions.tpl file, but that does not seem to work.

 

Than the code

{if $smarty.get.domain eq 'transfer' and $smarty.get.sld}

does not work.

 

How can I solve that?

Link to comment
Share on other sites

by the time you get to domainoptions, you'll lose access to those GET variables, but they'd almost certainly still exist under another name - you could try...

 

{if $checktype eq 'transfer' and $domain}

it really depends what you want to do with these values - but the above should tell you if it's a transfer or not.

Link to comment
Share on other sites

by the time you get to domainoptions, you'll lose access to those GET variables, but they'd almost certainly still exist under another name - you could try...

 

{if $checktype eq 'transfer' and $domain}

it really depends what you want to do with these values - but the above should tell you if it's a transfer or not.

 

Thanks!

 

But I also need to check if there is a sld in the URL.

 

I want to add a script, to auto clicks the transfer button when there is 'transfer' and a 'sld' in the URL.

Because this means that from outside our WHMCS the check is done that the domain can be transfered and I then want to auto click the transfer button.

 

But this should not happen when someone is checking a domain in the WHMCS cart.

 

So is it possible inside the domainoptions.tpl to check if the URL contains 'transfer' and 'sld'?

Link to comment
Share on other sites

But this should not happen when someone is checking a domain in the WHMCS cart.

So is it possible inside the domainoptions.tpl to check if the URL contains 'transfer' and 'sld'?

then we've come full circle - go back to a slightly modified version of your original code and it should work fine... :)

 

{if $smarty.server.HTTP_REFERER|strstr:'domain=transfer&sld='}

so if you follow your URL, the above should work... if you're just going through the cart normally, SLD won't be in the URL, so it shouldn't trigger. :idea:

Link to comment
Share on other sites

then we've come full circle - go back to a slightly modified version of your original code and it should work fine... :)

 

{if $smarty.server.HTTP_REFERER|strstr:'domain=transfer&sld='}

so if you follow your URL, the above should work... if you're just going through the cart normally, SLD won't be in the URL, so it shouldn't trigger. :idea:

 

That did the trick, amazing! Thanks :idea:

Link to comment
Share on other sites

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.   Paste as plain text instead

  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

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated