How to find the base url
Moderator: General Moderators
How to find the base url
I am having some problems. I need to take 2 urls and check to see if the base is the same. Meaning I need to take like http://www.google.com and pretty much remove the www. Except that I need it to work even if there is no www. meaning if it was forums.devnetwork.net and being checked against http://www.devnetwork.net it would say yes because the base is the same.
Have you looked at the values the variables $_SERVER has?
Code: Select all
echo '<HR><PRE>'; print_r($_SERVER); echo '</PRE>';Oops, read the post wrong. Ignore my last post.
Use substring to compare the URL.
Use substring to compare the URL.
Code: Select all
if(substr('www.myDoamin.com', 0, 4) == 'www.'){
//DO SOMETHINGAltough it's not completely clear what you are trying to do.
A possible approach is to use strpos to determine the first occurence of a . (http://www.example.org -> index = 4)
Then use this index to make substrings, so you keep example.org
A possible approach is to use strpos to determine the first occurence of a . (http://www.example.org -> index = 4)
Then use this index to make substrings, so you keep example.org
Do yea guys think something like this would work ok.
Code: Select all
$url = "http://www.devnetwork.com";
$url1 = "http://forums.devnetwork.com";
$new = parse_url($url);
$new1 = parse_url($url1);
$new_c = strpos($new['host'],".");
$new_d = substr($new['host'],$new_c+"1");
if (stristr($new1['host'],$new_d) != false){
echo "We are at the devnetwork!!!";
}else{
echo "We are not at the same place";
}ok that seems to be working pretty good. I have one other question. I do a select from my table of x amount of urls with a done value of 0. then while it is going through the result set I have it do an update for each url to change the done value to 1. It seems to work apache a lot harder now. Is there a way to maybe with an array of urls to do a batch update or something.
There is a potential for problems with the first position of . approach 
What happens if you have "i.am.example.org" and want to test if it is in the same domain as "example.org"?
Meaby it's better to test if the last parts (thus .example.org) of these strings are equal
If you have a dbms that supports subqueries:
What happens if you have "i.am.example.org" and want to test if it is in the same domain as "example.org"?
Meaby it's better to test if the last parts (thus .example.org) of these strings are equal
If you have a dbms that supports subqueries:
Code: Select all
UPDATE table
SET something=otherthing
WHERE table_id IN (
SELECT table_id with criteria that you used to select from my table of x amount of urls with a done value of 0
)I have mysql 5 I don't think it supports that. The base host will be what i put in. Will always be like http://www.google.com or something to that effect.