sc123 Posted April 4, 2008 Share Posted April 4, 2008 This is going to be very basic, but I can't figure it out! With the following code I'm simply trying to use "code A" if the user is anywhere under the /wp directory (Wordpress) and "code B" if they aren't. If anyone has suggestions on how to make this code work or make it better please feel free! <?php if ($path == "http://www.sitename.com/wp") : ?> <?php define('WP_USE_THEMES', false); ?> <?php else : ?> <?php define('WP_USE_THEMES', false); require('./wp/wp-blog-header.php'); ?> <?php endif; ?> Link to comment https://forums.phpfreaks.com/topic/99492-need-help-with-ifthen-statement/ Share on other sites More sharing options...
ansarka Posted April 4, 2008 Share Posted April 4, 2008 <?php if ($path == "http://www.sitename.com/wp") { define('WP_USE_THEMES', false); } else { define('WP_USE_THEMES', false); require('./wp/wp-blog-header.php'); } ?> Link to comment https://forums.phpfreaks.com/topic/99492-need-help-with-ifthen-statement/#findComment-509023 Share on other sites More sharing options...
sc123 Posted April 4, 2008 Author Share Posted April 4, 2008 Your code is much cleaner, thanks! It didn't work though as it still causes problems when browsing the wordpress part of the site. For example, if I use the following code: define('WP_USE_THEMES', false); require('./wp/wp-blog-header.php'); ...the rest of the site works as intended, but if I want to use the /wp part of the site correctly I can only use the following code: define('WP_USE_THEMES', false); The if/then statement would seem to perform this task, but for some reason it doesn't. Link to comment https://forums.phpfreaks.com/topic/99492-need-help-with-ifthen-statement/#findComment-509027 Share on other sites More sharing options...
sc123 Posted April 4, 2008 Author Share Posted April 4, 2008 It has been suggested to me that the path == will not work in this scenario and that I should use strcmp() - can anyone give me an example of what the syntax would be in this scenario? Link to comment https://forums.phpfreaks.com/topic/99492-need-help-with-ifthen-statement/#findComment-509345 Share on other sites More sharing options...
doni49 Posted April 4, 2008 Share Posted April 4, 2008 I don't know if I'd use strcmp. I'd be more inclined to go with egregi. www.php.net/eregi But for reference purposes, you can find info on strcmp here: www.php.net/strcmp EDIT: I almost forgot to say WHY I'd use eregi instead. With strcmp, the two strings have to be EXACTLY the same. What happens if the user types in "www.sitename.com/wp" or "HTTP://WWW.SITENAME.COM/wp"? or some other variation? you can deal with that using eregi. Link to comment https://forums.phpfreaks.com/topic/99492-need-help-with-ifthen-statement/#findComment-509351 Share on other sites More sharing options...
sc123 Posted April 4, 2008 Author Share Posted April 4, 2008 You're right in that they often won't be the same - also, what if there are looking at a WP post, then the path would be ./wp/?p=#. That's why I need something that can handle everything below the /wp dir. How could I use eregi to do that with this if/then? Link to comment https://forums.phpfreaks.com/topic/99492-need-help-with-ifthen-statement/#findComment-509368 Share on other sites More sharing options...
doni49 Posted April 4, 2008 Share Posted April 4, 2008 How could I use eregi to do that with this if/then? You can use wildcards with eregi. Also eregi is case INSENSITIVE while ereg is case SENSITIVE. Link to comment https://forums.phpfreaks.com/topic/99492-need-help-with-ifthen-statement/#findComment-509412 Share on other sites More sharing options...
sc123 Posted April 4, 2008 Author Share Posted April 4, 2008 What about fnmatch? It seems that some people use fnmatch with wildcards for exactly what I'm trying to do, though I still can't figure out how to incorporate this into my if/then... Link to comment https://forums.phpfreaks.com/topic/99492-need-help-with-ifthen-statement/#findComment-509434 Share on other sites More sharing options...
craygo Posted April 4, 2008 Share Posted April 4, 2008 If your code is going to be uses on other servers fnmatch is not a good idea. fnmatch only works on POSIX systems. So it will fail on a windows box. Just a heads up. Ray Link to comment https://forums.phpfreaks.com/topic/99492-need-help-with-ifthen-statement/#findComment-509437 Share on other sites More sharing options...
sc123 Posted April 4, 2008 Author Share Posted April 4, 2008 I have a linux server, so I thought it would be OK - it fails on Windows clients? Link to comment https://forums.phpfreaks.com/topic/99492-need-help-with-ifthen-statement/#findComment-509441 Share on other sites More sharing options...
craygo Posted April 4, 2008 Share Posted April 4, 2008 Not clients, windows servers. Web servers running windows. Link to comment https://forums.phpfreaks.com/topic/99492-need-help-with-ifthen-statement/#findComment-509447 Share on other sites More sharing options...
sc123 Posted April 4, 2008 Author Share Posted April 4, 2008 Yeah I should be fine then, but thanks for saying something just in case. Link to comment https://forums.phpfreaks.com/topic/99492-need-help-with-ifthen-statement/#findComment-509449 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.