Jump to content

[SOLVED] If the URL contains something, then add some html


RodrigoDC

Recommended Posts

Hello,

 

I've been working none stop for two days on a proyect and I have ran into a roadblock. I believe it is simpler than I think, so pardom my tireness please  :P

 

I need to create a simple statement that goes like this:

 

If the URL contains something like index.php?id=10, then do nothing, else, include some HTML, such as a table.

 

How would I do that?

 

Again, sorry if this overly basic, but my brain is fried. Thanks a million....

Link to comment
Share on other sites

My Gosh, and it only took an entire 10 minutes to figure out!!

 

Thanks!!

 

Orio's answer above appears more flexible in my case, since my URLs contain much more than just the ID, i.e., index.php?option=com_content&task=category&sectionid=4&id=16&Itemid=27.

 

Thanks to both Orio and Wes1890.

 

The forum rocks (even if my head's spinning  ;D

Link to comment
Share on other sites

<?php

if(strpos($url, "index.php?id=10") !== FALSE) //found
  ...
else //not found
  ...

?>

 

 

Orio.

 

Note that this will only return true if ID is the very first variable. so website.com/index.php?id=10&foo=bar will work.. but website.com/index.php?foo=bar&id=10 will not work. Also, website.com/someotherpage/?security=problem&index.php?id=10 will return true, when it obviously shouldn't. Just checking the _GET variable would probably be best in this situation.

Link to comment
Share on other sites

Actually, I don't believe the issue was solved.

 

Here is the code I have within my index.php template page:

 

										<?php
										if(strpos($url, "index.php?Itemid=54") !== FALSE) {
											?>
											hello world
											<?php
										}
										else {
											?>
										<img src="trans.gif" width="1" height="14" border="0" alt="spacer">
										<?php
										}
										?>

 

However, when I visit the page index.php?Itemid=54, I should see "Hello world", but no such luck. Am I missing something?

 

Thanks again in advance...

Link to comment
Share on other sites

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.