Jump to content

[SOLVED] select page based on URL?


tqla

Recommended Posts

I wish to have a page that will use includes to include text based on what's in the URL. Is it possible for PHP to read the URL?

 

Sort of like this:

 

<?php
if ( $url == "?services" ) {
<?php include("servicestext.php"); ?>";
}elseif ( $url == "?work" ){
        <?php include("worktext.php"); ?>";
}elseif  ( $url == "?travel" ){
        <?php include("traveltext.php"); ?>"; 
}
?>

 

How would I test the $url value?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/135212-solved-select-page-based-on-url/
Share on other sites

I think you want to use the $_GET method.  What does your URL look like?  And why do you keep opening and closing PHP tags when all you're using is PHP?

 

Ex: www.yoursite.com?your_var=services

 

$url = $_GET['your_var'];

if ($url == "services" ) {
   include("servicestext.php");
}elseif ( $url == "work" ) {
   include("worktext.php"); 
}elseif  ( $url == "travel" ) {
   include("traveltext.php");
}

Ooops. I just did the open and close tags out of habit while I was writing the post. Wow, that was bad. Thanks for correcting it.

 

My URLS will look like this:

 

http:// www . mysite . com / index?services

 

(I put in the spaces so a link would not be created)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.