Jump to content

PHP fallback system issue


Nitro7

Recommended Posts

Hello

 

I am trying to make a JS based content blocker with a PHP fallback if JS is disabled in the browser. What happens is that if the result is positive, JS sets a cookie and next time the user visits he/she is given direct access to the site without having to go through the content blocker. However, if the JS is disabled then the user is redirected to a PHP page which is supposed to work with cookies similar to its JS counterpart but I can't figure out how to get this to work, this is getting me stuck:

 

1. When the user is redirected to the PHP page, it checks if the user has set a cookie earlier in which case he/she should be redirected back to the home but as soon as the user lands on home, will be redirected to the PHP page as so on.

 

2. Is there a way to check for cookies within the <noscript> tags to avoid having to redirect to the PHP page?

 

 

Any suggestions for this? :)

Link to comment
Share on other sites

1. So either your cookie check doesn't work or you're not setting the cookies properly. Have you var_dump() 'ed the $_COOKIE var?

 

2. No.

 

But how is it supposed to work? 

 

Users visits the home page example.com

JS disabled so <noscript> tag redirected to example.com/fallbackSystem

example.com/fallbackSystem determines that a cookie was set earlier so redirects back to the home page

Users redirected back to the home page example.com

JS disabled so <noscript> tag redirected to example.com/fallbackSystem

 

That is the issue I am dealing with. Is there a possibility to tackle this while using a html page for example.com (no server side scripts and assuming JS disabled)

Edited by Nitro7
Link to comment
Share on other sites

 


JS disabled so <noscript> tag redirected to example.com/fallbackSystem

 

 

Noscript means no script, so you cannot redirect if JS is not enabled.

 

But javascript is not needed here. PHP can see if cookies were set and PHP can set cookies. If PHP detects that no cookies was set

it serves a page with the extra content and sets a cookie. If the cookie was set, PHP leaves the extra content out and doesn't set a cookie.

 

No javascript involved at all.

Link to comment
Share on other sites

That is the issue I am dealing with. Is there a possibility to tackle this while using a html page for example.com (no server side scripts and assuming JS disabled)

 

 

Actually, that isn't the issue. Seeing that the page visited at first is a html page and no server side scripting involved, would there be a workaround for this? It'll blindly redirect to the php fallback page which isn't a non js version of the original page but simply handles a validation task supposed to be done by JS at the home page. So after it has completed the validation task on the php page, it simply redirects to the original page with no JS function necessary this time around but since the <noscript> tag will tell the browser to go back to the php fallback page without having any ability to check for cookies it self (being a html page), this will put it into an infinite loop. Only issue arises due to the home page being a .html page, any possible workaround for this?

Edited by Nitro7
Link to comment
Share on other sites

Yes I read your response but quoted mine. My point being that the example.com page in the aforementioned process flow is a .html page so it will redirect to the php fallback page every time it is opened in a non JS browser. In case the JS is enabled, I am checking if a cookie exists on the same html page and never hide the content if it does but in case of non JS browser, it has to redirect to the PHP page to check if a cookie exist and even if a cookie is found, there is no way to tell that to the previous html page so when the php page redirects back to it, it'll again redirect to the PHP page. If you ask me, I don't see a workaround for this, but still?  

Link to comment
Share on other sites

 


Yes I read your response but quoted mine.

 

And did you understand what I posted? Because you are not asking questions about it, you just repeat what you've already said before, and coming to the same conclusion that what you are doing is weird and bad and doesn't work.

Link to comment
Share on other sites

Vinny is correct - create your page with PHP. That will save you a bunch of headaches. Since PHP is executed first, you can detect cookies immediately and serve the correct content without JavaScript or redirects or the noscript tag.

 

Seriously, you're way overthinking this.

Link to comment
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.