Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7615551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:40:13+00:00 2026-05-31T02:40:13+00:00

I am doing a php portal. i did an announcement section where user can

  • 0

I am doing a php portal.

i did an announcement section where user can post message and attach a file.

so in this situation, a user has uploaded one and at the page, there will be a hyperlink for the attachment. if i hover on it, i can see this “192.168.0.100/Announcement/file.pdf”

so logically if im in the internal network and click on that it would not be a problem as it can get the file from that ip.

next situation is i have forwarded the server ip so that public can access from outside. now i’m as a user accessing from outside.

so if i were to go to the announcement location and hover on it again it will show the same link “192.168.0.100/Announcement/file.pdf”. I will definitely wont be able to open it as that ip is internal.

so i am thinking how can i make it when i’m internal, the ip is the internal one and when im outside,the ip link would be the public?

i got this snippet from a ex colleague but i dont really know what the code does. Can someone help me explain this? i tried searching this thing i want to do on the net,but i dont have a proper keyword for it.

below is the snippet:

<?php
//filename constant.php

define('SERVERIP',((preg_match("/^192\.168/i",$_SERVER['REMOTE_ADDR']))?'192.168.0.100':'175.136.xxx.xxx'),true);
?> 

And below is part of the code in the page for the announcement and attachment:

include('_include/constant.php');
$dir = "C:/Inetpub/wwwroot/Announcement/";
$http = sprintf('http://%s/Announcement/',SERVERIP);

print '<td class="middle '.$CLASS.'" align="left" height="20">'.'<a href="http://'.SERVERIP.'/Announcement/'.$filename.'" target="_blank">'.$filename .'</a></td>';

Can any php pros here help me to understand whats happening so that next time i know what i’am actually implementing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:40:14+00:00Added an answer on May 31, 2026 at 2:40 am

    What you have is a ternary operation, the results of which are being assigned to the constant SERVERIP. It is using a regex to match against the $_SERVER['REMOTE_ADDR'], if it begins with 192.168, then it gets the 192.168 value, otherwise it gets the 175.136 value. And for some reason it is passing true to enforce a case insensitive search.

    You can read more on define within the PHP docs.

    Lighter example of ternary op:

    $overlyComplex = true;
    
    $thatDudesCodeSucks = (true === $overlyComplex) ? 'yes' : 'no';
    
    // Shorthand for
    if (true === $overlyComplex) {
        $thatDudesCodeSucks = 'yes';
    } else {
        $thatDudesCodeSucks = 'no';
    }
    
    var_dump($thatDudesCodeSucks); // echos yes
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since PHP has no custom-class type-casting, how would I go about doing the PHP
This should a quick question for some easy rep. I'm doing some PHP Website
So I am thinking of doing my PHP in OO way. Can someone tell
shell_exec() : I'm doing a PHP site that uses a shell_exec() function like this:
What on earth is PHP doing here? This first line works perfectly, but when
I'm going to be doing some PHP editing for my job this summer, and
Regarding performance, is there any difference between doing: $message = The request $request has
I'm doing a PHP cURL post, using a complete URL (http://www.mysite.com), from one page
I've been doing PHP/MySQL websites with shared hosting providers for the last couple years.
I have been doing PHP stuff for almost one year and I have never

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.