Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-24-2010, 02:32 PM help with php ...
ZoC
Skilled Talker

Posts: 68
Trades: 0
Hello there, i have one problem and i dont know how to fix ...

my command:

HTML Code:
<?php
 if (preg_match("~^http://www.google.com~i", $_SERVER['HTTP_REFERER']))
  {
  echo 'Google Referer';
  } else {
  echo 'No Referer';
  } 
 }
?>
how i can add 2 preg_match ? example: if http://www.google.com and http://search.yahoo.com = $_SERVER['HTTP_REFERER'] echo 'Google Referer';

and one more thing, how i can add just google.com no "~^http://www.google.com~i" i try "~^google.com~i" but its not working ...

Last edited by ZoC; 04-24-2010 at 02:34 PM..
ZoC is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-25-2010, 04:43 AM Re: help with php ...
Novice Talker

Posts: 4
Trades: 0
PHP Code:
<?php
 
if (preg_match('(.*google.com.*)'$_SERVER['HTTP_REFERER']) || preg_match('(.*search.yahoo.com.*)'$_SERVER['HTTP_REFERER']))
  {
  echo 
'Google Referer';
  } else {
  echo 
'No Referer';
  } 
 }
?>
You could try something like that.
ghis is offline
Reply With Quote
View Public Profile
 
Old 04-25-2010, 08:50 AM Re: help with php ...
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
No need to use a regular expression. One of my favorite PHP functions is this: strpos(). It returns the position that a string was found, and is also very handy for finding out if it exists within any string. For simple matches this is all that is needed.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 04-25-2010, 10:25 AM Re: help with php ...
ZoC
Skilled Talker

Posts: 68
Trades: 0
hello there, thanks for all your answer help me alot !

i have one more question if someone can help me

------------------------------------
website url: http://www.website.com/?w=youtube.com

$w = $_REQUEST['w'];
if ($w != "youtube.com") { } else { echo 'youtube.com'; }
------------------------------------

------------------------------------
website url: http://www.website.com/?w=google.com

$w = $_REQUEST['w'];
if ($w != "google.com") { } else { echo 'google.com'; }
------------------------------------

how i can make if $w is not youtube.com or google.com (or is another link example: facebook.com) to show echo 'none';
ZoC is offline
Reply With Quote
View Public Profile
 
Old 04-25-2010, 10:39 AM Re: help with php ...
Marik's Avatar
Skilled Talker

Posts: 99
Trades: 0
If you do decide to use strpos instead of regular expressions here's how:

PHP Code:
<?php

if (strpos($_SERVER['HTTP_REFERER'], "google")) {
    echo 
"Google Referer";
} else {
    echo 
"No Referer";
}

?>
Quote:
Originally Posted by ZoC View Post
hello there, thanks for all your answer help me alot !

i have one more question if someone can help me

------------------------------------
website url: http://www.website.com/?w=youtube.com

$w = $_REQUEST['w'];
if ($w != "youtube.com") { } else { echo 'youtube.com'; }
------------------------------------

------------------------------------
website url: http://www.website.com/?w=google.com

$w = $_REQUEST['w'];
if ($w != "google.com") { } else { echo 'google.com'; }
------------------------------------

how i can make if $w is not youtube.com or google.com (or is another link example: facebook.com) to show echo 'none';
I'm not sure I understand your question properly, but maybye this is what you mean:

PHP Code:
website urlhttp://www.website.com/?w=youtube.com

$w $_REQUEST['w'];
if (
$w != "youtube.com") { echo 'None' } else { echo 'youtube.com'; }

website urlhttp://www.website.com/?w=google.com

$w $_REQUEST['w'];
if (
$w != "google.com") { echo 'None' } else { echo 'google.com'; } 

Last edited by Marik; 04-25-2010 at 10:41 AM..
Marik is offline
Reply With Quote
View Public Profile
 
Old 04-25-2010, 02:53 PM Re: help with php ...
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Quote:
Originally Posted by Marik View Post
If you do decide to use strpos instead of regular expressions here's how:

PHP Code:
<?php

if (strpos($_SERVER['HTTP_REFERER'], "google")) {
    echo 
"Google Referer";
} else {
    echo 
"No Referer";
}

?>
Actually, that's not quite how I'd do it. Although it will work, it would also match websites such as ihategoogle.com, or googlerules.com or googlesucks.com or anything that has the "google" substring in it, even just a link from a site with a directory called or containing google.

but:

PHP Code:
if (strpos($_SERVER['HTTP_REFERER'], "//www.google.") || strpos($_SERVER['HTTP_REFERER'], "//google.")) {
    echo 
"Google Referer";
} else {
    echo 
"No Referer";

will be rock solid.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.

Last edited by wayfarer07; 04-25-2010 at 02:54 PM..
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 04-25-2010, 02:59 PM Re: help with php ...
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Then again, my example isn't rock solid either after all, because you could have the above strings in a query string or even in the path, in theory, and it would give a false positive. You'll need to go all the way to http:// or https:// and make sure this is the very first thing in the string:

PHP Code:
if (strpos($_SERVER['HTTP_REFERER'], "http://www.google.") === || strpos($_SERVER['HTTP_REFERER'], "http://google.") === ||  strpos($_SERVER['HTTP_REFERER'], "https://www.google.") === || strpos($_SERVER['HTTP_REFERER'], "https://google.") === 0) {
    echo 
"Google Referer";
} else {
    echo 
"No Referer";

__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 04-25-2010, 06:36 PM Re: help with php ...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It would be more efficient to use a switch construct as there is more than one "Google" and more than one search engine.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to help with php ...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27417 seconds with 12 queries