Jump to content

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)

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.