0

I know the title may be confusing but essentially I'm using the $_GET method for a variable and I cannot use it if there is a #check infront of it.

For example: http://this.org/#check?whatever=1

So naturally if I check for the variable like this:

if ($_GET['whatever'] == 1) {

}

It won't work. So what can I add perhaps infront of the 'whatever' when I check for it to make it work? If i don't have the #check infront of the url the entire website refreshes. Any help would be appreciated, thanks for your time.

John Leo
  • 55
  • 7
  • or you can just make an xmlhttprequest instead – Kevin Dec 09 '16 at 02:50
  • "If i don't have the #check infront of the url the entire website refreshes." Is this the only reason you're using `#check`, or does it have another purpose? – ChrisGPT was on strike Dec 09 '16 at 02:50
  • Yes that's the only reason @Chris. – John Leo Dec 09 '16 at 02:59
  • @Ghost is there really no other way I can do without xmlhttprequest? – John Leo Dec 09 '16 at 03:00
  • after the hash, it doesn't get sent on the server, just make an xmlhttprequest if you don't want the whole page to reload, its just few lines – Kevin Dec 09 '16 at 03:04
  • Damn, time to do some research. – John Leo Dec 09 '16 at 03:08
  • @Ghost Can you specify in a little bit more detail what exactly I need to do pertaining to xmlhttprequest so I know what to research? – John Leo Dec 09 '16 at 03:18
  • @JohnLeo if this url is supposed to be sent thru an anchor link, just let javascript handle the event, then under that, get the hash value, then some processing that you need, then make the request, after that, the PHP side processes the request and make the appropriate response, here's a bare simple example http://stackoverflow.com/questions/27458258/onclick-javascript-on-anchor-tag-html – Kevin Dec 09 '16 at 03:28
  • @Ghost If the whole page doesn't refresh though will it still update the variable? – John Leo Dec 09 '16 at 03:50

1 Answers1

0

I don't know if you mean something like this. But see if this helps.

var url = "http://this.org/#check?whatever=1";

var splitQuestionMark = url.split('?');

var findCheck = splitQuestionMark[0].split('/');

if(findCheck[findCheck.length-1]==="#check")
{
    // use GET
}
else
{
    // don't use GET
}
Ishwor Timilsina
  • 1,344
  • 12
  • 11