Computing.Net > Forums > Web Development > PHP Include Help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

PHP Include Help

Reply to Message Icon

Name: veachian64
Date: January 29, 2005 at 16:38:35 Pacific
OS: Windows XP Pro
CPU/Ram: 224MB Ram
Comment:

I am using PHP include code <?php if($page == "") { include "updates.txt"; } else { include "$page.txt"; } ?> on my website, http://www.animeplanetnet.net, and my host does support PHP, but whenever I click a link, it does not take you to the requested page, but simply stays on the main page. Can someone tell me what I am doing wrong?



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: January 29, 2005 at 17:29:36 Pacific
Reply:

I think the problem is in your use of the variable $page. You are using it correctly in the comparrison part of your if statement, but it is not correct in the include statement.

By including $page in quotes, it is no longer treating it as a variable. Instead you can try:

include $page.".txt";

I haven't tried combining strings within the include statement, si I'm not 100% sure if that will work, but if it doesn't then creating a single variable with the full page name first will. Such as:

$page = $page.".txt";
include ($page);

I do something similar on one of my sites, but I use a Switch statement in my main page like this:

switch ($name) {
  case "":
  case "home":
    $title = "Repeat Offenders";
    $page = "home.php";
    break;
  case "downloads":
    $title = "Repeat Offenders: Downloads";
    $page = "downloads.php";
    break;

Then as I'm building the page I dynamically create the page title with the $title variable and call the content with the page variable using include($page)

Michael J


0

Response Number 2
Name: Michael J (by mjdamato)
Date: January 29, 2005 at 17:30:51 Pacific
Reply:

Sorry, my first ewxmple was missing hte parens. Should look like this:

include ($page.".txt");

Michael J


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


html help!! Rate my Website Layout



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: PHP Include Help

How to protect PHP includes? www.computing.net/answers/webdevel/how-to-protect-php-includes/1029.html

php/mysql help www.computing.net/answers/webdevel/phpmysql-help/3524.html

php help needed www.computing.net/answers/webdevel/php-help-needed/2399.html