RodrigoDC Posted November 21, 2007 Share Posted November 21, 2007 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 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.... Quote Link to comment https://forums.phpfreaks.com/topic/78227-solved-if-the-url-contains-something-then-add-some-html/ Share on other sites More sharing options...
Wes1890 Posted November 21, 2007 Share Posted November 21, 2007 Just check the URK: if ($_GET['id'] == 10) { // do nothing } else { // do something } The $_GET[] array contains what is in your URL (in this case, index.php?id=10) Quote Link to comment https://forums.phpfreaks.com/topic/78227-solved-if-the-url-contains-something-then-add-some-html/#findComment-395870 Share on other sites More sharing options...
Orio Posted November 21, 2007 Share Posted November 21, 2007 <?php if(strpos($url, "index.php?id=10") !== FALSE) //found ... else //not found ... ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/78227-solved-if-the-url-contains-something-then-add-some-html/#findComment-395873 Share on other sites More sharing options...
RodrigoDC Posted November 21, 2007 Author Share Posted November 21, 2007 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§ionid=4&id=16&Itemid=27. Thanks to both Orio and Wes1890. The forum rocks (even if my head's spinning Quote Link to comment https://forums.phpfreaks.com/topic/78227-solved-if-the-url-contains-something-then-add-some-html/#findComment-395884 Share on other sites More sharing options...
Azu Posted November 21, 2007 Share Posted November 21, 2007 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/78227-solved-if-the-url-contains-something-then-add-some-html/#findComment-395935 Share on other sites More sharing options...
RodrigoDC Posted November 21, 2007 Author Share Posted November 21, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/78227-solved-if-the-url-contains-something-then-add-some-html/#findComment-395957 Share on other sites More sharing options...
Orio Posted November 21, 2007 Share Posted November 21, 2007 But $url doesn't contain the current URL... You need to define it: $url = basename($_SERVER['PHP_SELF'])."?".$_SERVER['QUERY_STRING']; Orio. Quote Link to comment https://forums.phpfreaks.com/topic/78227-solved-if-the-url-contains-something-then-add-some-html/#findComment-395961 Share on other sites More sharing options...
RodrigoDC Posted November 21, 2007 Author Share Posted November 21, 2007 Yes, Orio, you were absolutely correct! My apologies. This is just a symptom of my 39th. hour without the pleasures of sleep. In fact, if ($_GET['id'] == 10) does the trick beautifully. Kudos Orio...and good night! Quote Link to comment https://forums.phpfreaks.com/topic/78227-solved-if-the-url-contains-something-then-add-some-html/#findComment-395963 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.