Solved

PHP Syntax

Posted on 2013-05-13
3
182 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
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…

726 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