Solved

PHP Syntax

Posted on 2013-05-13
3
181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 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