rockinaway Posted May 12, 2007 Share Posted May 12, 2007 I want to check the URL, and if it is the one I am looking for, then I want to show something. So how would I check the URL? Quote Link to comment https://forums.phpfreaks.com/topic/51102-checking-url/ Share on other sites More sharing options...
Broniukas Posted May 12, 2007 Share Posted May 12, 2007 you can open a file handled in server, if it's exist - server online . or use fsockopen() $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30); Quote Link to comment https://forums.phpfreaks.com/topic/51102-checking-url/#findComment-251555 Share on other sites More sharing options...
rockinaway Posted May 12, 2007 Author Share Posted May 12, 2007 No you see I have my homepage, but it will also show on other pages of my website, where I don't want it to.. So I want to check the website address the user is currently at, and if it is the homepage, then I want it to display the homepage, if not then I don't want to show anything.. is this possible with PHP? Quote Link to comment https://forums.phpfreaks.com/topic/51102-checking-url/#findComment-251557 Share on other sites More sharing options...
Broniukas Posted May 12, 2007 Share Posted May 12, 2007 $_SERVER['PHP_SELF'] $_SERVER['SERVER_NAME'] check this for more $_SERVER variables http://lt2.php.net/reserved.variables Quote Link to comment https://forums.phpfreaks.com/topic/51102-checking-url/#findComment-251566 Share on other sites More sharing options...
rockinaway Posted May 13, 2007 Author Share Posted May 13, 2007 Right if I use $_SERVER['PHP_SELF'] on a page it shows index.php .. But the problem is I have 2 locations... - index.php - index.php?cat=12 ... I only want to show it for the index.php and not the cat=12 one.. can I limit this? Quote Link to comment https://forums.phpfreaks.com/topic/51102-checking-url/#findComment-251863 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 <?php if(!isset($_GET['cat'])) { // Code here for when the page is accessed without ?cat= on the URL } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51102-checking-url/#findComment-251864 Share on other sites More sharing options...
rockinaway Posted May 13, 2007 Author Share Posted May 13, 2007 Sorry didn't explain it correctly.. Any page without index.php only should not be able to show.. isn't there a global sign I can use to symbolise anything after the .php? So index.php should so it.. but, for example, index.php?f=23, index.php?g=343, index.php?h=434 all should not.. Quote Link to comment https://forums.phpfreaks.com/topic/51102-checking-url/#findComment-251866 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 <?php foreach($_GET as $k => $v) { $get = true; } if($_SERVER['PHP_SELF'] == "index.php" && !$get) { // Display code } ?> There's probably a cleaner way but that will work Quote Link to comment https://forums.phpfreaks.com/topic/51102-checking-url/#findComment-251871 Share on other sites More sharing options...
Daniel0 Posted May 13, 2007 Share Posted May 13, 2007 <?php if(count($_GET) != 0) { die(); } // rest of code... ?> Quote Link to comment https://forums.phpfreaks.com/topic/51102-checking-url/#findComment-251879 Share on other sites More sharing options...
rockinaway Posted May 13, 2007 Author Share Posted May 13, 2007 It has all gone now :S EDIT - my bad .. IT WORKS WELL GOOD! .. Even sorted other problems I had ... thanks Daniel.... Quote Link to comment https://forums.phpfreaks.com/topic/51102-checking-url/#findComment-251881 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.