简体   繁体   English

如何使用php三元运算符重定向到默认服务器索引页?

[英]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 ? 我曾尝试使用php三元运算符检查服务器名称协议?

Here is example and code: 这是示例和代码:

Example: https://9.218.145.189 例如: 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 . 如果我的HTTP / HTTPS是打开/关闭,当我单击href链接(即9.218.145.189)时,它应该将我重定向到https://9.218.145.189主页,而不是将我重定向到https://9.212.145.189/ outpt.php

Error: 错误:

THe above code for a href link is not taking me to the https link. 上面的href链接代码无法将我带到https链接。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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