Jump to content

Strpos


Hareuhal

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.