0

OK, this is what I'm trying to do. I created a variable:

$current = $_SERVER['SERVER_NAME'];

and then I want to concatenate the var in an include:

<?php include ($current . 'includes/mysection.php') ?>

but is showing nothing. What am I doing wrong? Thanks.

Labanino
  • 3,902
  • 9
  • 33
  • 51
  • 2
    I assume there's meant to be a slash there? – alex Apr 16 '14 at 02:02
  • 1
    you're trying to include a file using an http location, such as `localhostincludes/mysection.php` (the lack of a slash is what your result looks like, btw), which based on the name `includes`, i doubt is what you want – Ohgodwhy Apr 16 '14 at 02:02
  • 1
    also, you could try echoing that ($current . 'includes/mysection.php') to verify the result is indeed a valid path and what you are expecting – Kai Qing Apr 16 '14 at 02:07

1 Answers1

0

$_SERVER['SERVER_NAME'] gives teh value of the server name as defined in host configuration (i.e for Apache the Apache .conf file).

Thus, it prints:

SERVER_NAME = domain.com

Note that the slash does not have to end. Place the slash like this:

<?php include ($current . '/includes/mysection.php') ?>

When using the $_SERVER['SERVER_NAME'] variable in an apache virtual host setup with a ServerAlias directive, be sure to check the UseCanonicalName apache directive. If it is On, this variable will always have the apache ServerName value. If it is Off, it will have the value given by the headers sent by the browser.

Depending on what you want to do the content of this variable, put in On or Off.

Font: http://www.php.net/manual/en/reserved.variables.server.php

Font: PHP: $_SERVER variables: $_SERVER['HTTP_HOST'] vs $_SERVER['SERVER_NAME']

Community
  • 1
  • 1
Lucas Henrique
  • 1,380
  • 1
  • 11
  • 15