kenjisi Posted May 23, 2017 Share Posted May 23, 2017 How to show div based on specific URL in PHP (if statement)? For example, we have these URL: http://www.abc.com/about/ http://www.abc.com/background/ http://www.abc.com/contact/ Show this div for http://www.abc.com/about/ <div>This is About</div> This div for http://www.abc.com/background/ <div>This is Background</div> This div for http://www.abc.com/contact/ <div>This is Contact</div> Quote Link to comment Share on other sites More sharing options...
benanamen Posted May 23, 2017 Share Posted May 23, 2017 (edited) Rather than crowd your page with a bunch of unrelated information you can use includes to display the relevant information. Optimally, you want a single point of entry to your site, index.php and then include the relevant pages based on the URL. Without pretty URL's: index.php?p=about, index.php?p=contact, etc... You're allowed pages should be whitelisted in an array so users cannot try to randomly include pages. There is code on the forum from @Jaques1 that will show you how to do this. Edited May 23, 2017 by benanamen Quote Link to comment Share on other sites More sharing options...
kenjisi Posted May 23, 2017 Author Share Posted May 23, 2017 Thanks Benanamen! For some reasons (not technical) my access not allow me to use includes but i need to make this things happen. Are there any code similar like this to get things works: <?php if(xxxx..http://www.abc.com/about/){ echo '<div>contents</div>'; } ?> Sorry if i asking something stupid, Im new to php. Quote Link to comment Share on other sites More sharing options...
benanamen Posted May 23, 2017 Share Posted May 23, 2017 You might be thinking of server-side includes. PHP includes is a standard part of PHP. Look it up in the manual. Quote Link to comment 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.