简体   繁体   中英

How to redirect to default server index page using php ternary operator?


I had tried to check the server name protocol using php ternary operator ?

Here is example and code:

Example: https://9.218.145.189

example code:

<a href="<?php echo $SERVER['SERVER_NAME']=($_SERVER['SERVER_NAME'])?($_SERVER['SERVER_NAME']=='ON'):($_SERVER['SERVER_NAME']=='OFF');?>">Click here</a>

QUery:

  1. If my HTTP/HTTPS is ON/OFF it should redirect me to the https://9.218.145.189 home page when i click href link(ie 9.218.145.189) instead it is redirecting me to the https://9.212.145.189/outpt.php .

Error:

THe above code for a href link is not taking me to the https link.

FYI:

= is assignment operator

== is comparision operator

Hence try the following code(modified):

<a href="<?php echo $SERVER['SERVER_NAME']=($_SERVER['SERVER_NAME'])?($_SERVER['SERVER_NAME']='ON'):($_SERVER['SERVER_NAME']='OFF'); ?>">Click here</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM