Solved

PHP Syntax

Posted on 2013-05-13
3
174 Views
Last Modified: 2013-05-13
Hi

$Webhost = www.tdl.com;

if ($_SERVER['HTTP_HOST'] !== '$WebHost')

$AbsolutePath = $_SERVER['DOCUMENT_ROOT']."info_here";
$SubDomainHomePath = "info_here";

else

$AbsolutePath = $_SERVER['DOCUMENT_ROOT']."info_here";
$SubDomainHomePath = "info_here";
)
0
Comment
Question by:Computer Guy
  • 2
3 Comments
 
LVL 6

Expert Comment

by:BurundiLapp
ID: 39161018
if ($_SERVER['HTTP_HOST']  !==  $WebHost)

First thought is that you are enclosing the variable in single quotes which means it won't parse the variable, it will treat it as text.  remove the single quotes or replace with double quotes.
0
 
LVL 6

Accepted Solution

by:
BurundiLapp earned 500 total points
ID: 39161023
Full thing would be:

$Webhost = www.tdl.com;

if  ($_SERVER['HTTP_HOST']  !==  $Webhost)
{
  $AbsolutePath = $_SERVER['DOCUMENT_ROOT']."info_here";
  $SubDomainHomePath = "info_here";
}
else
{
  $AbsolutePath = $_SERVER['DOCUMENT_ROOT']."info_here";
  $SubDomainHomePath = "info_here";
}

Open in new window


Correct capitalisation of variables is important as well, keep it constant or PHP gets confused.

http://uk3.php.net/manual/en/control-structures.if.php
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39161129
The values of HTTP_HOST and DOCUMENT_ROOT are not immutable.  They are determined by the PHP installation and can be changed by scripts running on the server.  HTTP_HOST can also be affected by rewrite rules.  You may find that what works on one server does not work on another server, so be careful when relying on these values.  

The term "subdomain" is a term of art in web applications.  Please see this link.

As a general rule, HTTP_HOST contains the domain name and will look something like www.example.com.  DOCUMENT_ROOT contains the server path to the "home" directory and will look something like /home/example/public_html.  

Case Sensitivity: Variables, object properties and array indexes are case-sensitive.  The names of functions, classes and methods are not case-sensitive.  Coding standards often call for capitalization of class names or camelCase for methods.  In MySQL the data elements are not case-sensitive unless you ask SQL to treat them that way, however the names of tables and columns are case-sensitive.  File systems are not case-sensitive in Windows, but are case-sensitive in Linux.

Special Characters: To help you write PHP code that is compatible across releases and systems, PHP defines two important special constants.  This is because the values are different depending on the current operating system.  DIRECTORY_SEPARATOR is the value of the slash (or backslash) that is used in file paths.  PHP_EOL is the end-of-line character.  It's wise to use these instead of hardcoding a slash or a slash-n.

A good book that will help you get a foundation in the way PHP works is available here.
http://www.amazon.com/PHP-MySQL-Web-Development-Edition/dp/0672329166/
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now