Current location: Hot Scripts Forums » Programming Languages » PHP » Including content


Including content

Reply
  #1 (permalink)  
Old 09-16-04, 05:51 PM
rjwebgraphix rjwebgraphix is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Including content

This should be the last question with what I'm currently working on....

Loading the content the code works fine. Using if/elseif statements to find what the extention is. Maybe I'm thinking about it too much, but I wanted to put something that if by chance the url got changed it would redirect back to the home page.

This is the original code:
PHP Code:

<?php 

    
if(file_exists("$content.html")){
     include (
"$content.html");
    } elseif (
file_exists("$content.php")){
     include (
"$content.php");
    } elseif (
file_exists("$content.txt")){
     include (
"$content.txt");
    } elseif (
file_exists("$content")){
     include (
"$content");
    } else{
     echo 
"page cannot be found";
    }
 
?>
This sorta works. It will display the home page, but the url typed will show the bogus address. IE: www.mysite.com/index.php?content=bogusaddress will display the home page, but it's not the right address. I'd like to actually redirect them back to the home page.

PHP Code:

<?php 

        
if(file_exists("$content.html")){ 
         include (
"$content.html"); 
        } elseif (
file_exists("$content.php")){ 
         include (
"$content.php"); 
        } elseif (
file_exists("$content.txt")){
     include (
"$content.txt"); 
        } elseif (
file_exists("$content")){ 
         include (
"$content");
    } else{ include (
"home.html"); } ?>
Can php redirect the url itself? I can't seem to find anything in PHP to do that. Or... will I need to echo a javascript redirector? at the "else"?

Thanks,
RJ
Reply With Quote
  #2 (permalink)  
Old 09-16-04, 07:52 PM
ThePatronus HP ThePatronus HP is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Talking

Here you go...this is how you work a redirect link for PHP. Basically, the same as HTML, except you need to work it with PHP. It's easy.

PHP Code:

<?php 

if(file_exists("$content.html"))

   include (
"$content.html"); 
}
elseif (
file_exists("$content.php"))

   include (
"$content.php"); 
}
elseif (
file_exists("$content.txt"))

   include (
"$content.txt"); 
}
elseif (
file_exists("$content"))

   include (
"$content");
}
else
{
   echo 
"<meta http-equiv=refresh content=0;url=home.html>";
}
?>
Reply With Quote
  #3 (permalink)  
Old 09-16-04, 09:08 PM
rjwebgraphix rjwebgraphix is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by ThePatronus HP
Here you go...this is how you work a redirect link for PHP. Basically, the same as HTML, except you need to work it with PHP. It's easy.
Thanks that worked, just needed to modify slightly to the correct url.

Code:
   echo "<meta http-equiv=refresh content=0;url=./index.php?content=home>";
I'm wondering just one thing. Why have I been using a javascript to do redirection all these years?

Thanks again,
RJ
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
linking to both iframe content and parent page vman2957 HTML/XHTML/XML 5 12-02-06 12:49 AM
Error On Registeration timmy408 ASP 2 09-05-04 02:53 PM
how to protect content on site MaritimeSource PHP 17 08-17-04 07:23 AM
forcing an iframe to scrolldown as it gets filled with content davidklonski JavaScript 2 07-20-04 08:27 AM
how to protect content on site MaritimeSource HTML/XHTML/XML 3 04-27-04 10:33 AM


All times are GMT -5. The time now is 04:29 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.