Is it safe to use this code with WordPress to get cloudflare SSL working

Posted October 15, 2021 140 views

I want to ask if this code snippet is safe to use in WordPress. As I am new and their are many experts here. So I would like to ask them about this code.

if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] ) { $_SERVER['HTTPS'] = 'on'; }

This code solves the redirect loop when using cloudflare SSL certificate.

Many forums and threads I have suggested to use similar code but some say that $_SERVER['HTTPS'] = 'on'; using this code is not a good practice. I want someone to guide

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Yes, its found ok. If any issue kindly ping me.