Hareuhal Posted December 15, 2010 Share Posted December 15, 2010 Hey guys I need some help I did a quick search and couldn't find my problem so I hope I didn't miss it. Anyways, I've got a bit of code in which when a specific website is visited, it generates a log. This is to track the number of times the website gets visited and from where. I know this sounds like a counter, but it's different. I'm having a problem though, because right now, I can't get it to generate for ONLY the website entered. It generates for EVERY website instead of just the specific one. Right now this is what I have.. if (strpos($_url, "MY_SPECIFIC_WEBSITE") //URL { I've tried adding to it to fix it, but I'm obviously still learning PHP and am sick of strugglnig. If anyone could please help I would appreciate it so much. Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted December 15, 2010 Share Posted December 15, 2010 I think the key is that strpos can return a boolean FALSE or TRUE, so you would normally want to test for FALSE or TRUE: if(strpos($haystack, $needle) !== FALSE) { } // or if(strpos($haystack, $needle) === FALSE) { } Quote Link to comment Share on other sites More sharing options...
Hareuhal Posted December 15, 2010 Author Share Posted December 15, 2010 I think the key is that strpos can return a boolean FALSE or TRUE, so you would normally want to test for FALSE or TRUE: if(strpos($haystack, $needle) !== FALSE) { } // or if(strpos($haystack, $needle) === FALSE) { } Thanks for the response. Would you be able to please show me what I would have to do then? I understand I would need a true or false, I'm just having difficulty getting it right. I also forgot to mention that it's generating logs for the content on the pages. So if theres content linked to that URL, but still different (say instead of wwwwwww.com, it's awwwwww.com , it's still generating the logs. I need it to literally ONLY generate for the ONE url I put in, nothing else. Thank you. Quote Link to comment Share on other sites More sharing options...
Hareuhal Posted December 15, 2010 Author Share Posted December 15, 2010 Bump, anyone, please. All I really need to be able to do is have an action occur for ONLY the specified URL, out of any...so it needs to be able to read every single URL entered, but only trigger on the URL's I want it to. anyone, please? Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted December 15, 2010 Share Posted December 15, 2010 Bump, anyone, please. All I really need to be able to do is have an action occur for ONLY the specified URL, out of any...so it needs to be able to read every single URL entered, but only trigger on the URL's I want it to. anyone, please? What do you mean every URL entered? Show code for that and the specific URL, with examples. Quote Link to comment Share on other sites More sharing options...
Hareuhal Posted December 15, 2010 Author Share Posted December 15, 2010 Say if I want it to generate for website1.com, and ONLY website1.com, it still generates for google.com, yahoo.com, or any other website. More or less I just need a line of code which can pick out SPECIFIC URL's from any URL entered. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted December 15, 2010 Share Posted December 15, 2010 Say if I want it to generate for website1.com, and ONLY website1.com, it still generates for google.com, yahoo.com, or any other website. More or less I just need a line of code which can pick out SPECIFIC URL's from any URL entered. Give examples of what should work. Quote Link to comment Share on other sites More sharing options...
Hareuhal Posted December 15, 2010 Author Share Posted December 15, 2010 if (strpos($_url, 'MYWEBSITEHERE')) That's what I have, but the problem is that it's not limiting it to just that. I can remove that code entirely and it will still generate a log for any website visited, instead of just the specified one. I was thinking of preg_match but I've no idea how to set it up. A lot of people use them to add things like http:// to a URL, but I need to restrict it to ONLY the URL entered, so I'm totally lost. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted December 15, 2010 Share Posted December 15, 2010 Well, sKunKbad gave the answer, did you try it? $_url = 'http://www.example.com'; if (strpos($_url, 'example.com') !== false) { echo "Match"; } else { echo "No match"; } Quote Link to comment Share on other sites More sharing options...
Hareuhal Posted December 15, 2010 Author Share Posted December 15, 2010 Yes I did try it. No good. Before I even added my code to it, I wanted to see if it would display Match / No Match respectively. I had the website set to facebook.com for example, no matter what website I'd visit, it would report that it matched. This is what I had $_url = 'facebook.com'; if (strpos($_url, 'facebook.com') !== false) { echo "Match"; } else { echo "No Match"; } Any ideas? Thanks. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted December 15, 2010 Share Posted December 15, 2010 I have no idea what you're talking about. What do you mean by "visit"? The code you posted echos Match. This code: $_url = 'google.com'; if (strpos($_url, 'facebook.com') !== false) { echo "Match"; } else { echo "No Match"; } Echos No Match. 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.