/    Sign up×
Community /Pin to ProfileBookmark

set recordset value based on domain name

Hi,

I am a newbie around here – so let me start by saying, what a great resource!

I am trying to set the value of a recordset to the domain name that is querying the database.

For instance – I have a PHP page that accesses a MySQL database, but needs to know the textual domain name (just the name – not the www or www2 whatever) of the web site requesting the MySQL query.

It sounds confusing, I hope someone can understand my jiberish.

Thanks for the help (found many answers here in the past)

Daniel

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@96turnerriOct 20.2004 — [code=php]<?php echo $_SERVER["SERVER_NAME"]; ?>[/code]
Copy linkTweet thisAlerts:
@dollarguyauthorOct 21.2004 — Thanks...

That gives me the full (www.domain.com) How do I reduce it to just the domain name. (domain.com)

Thanks again,

Daniel
Copy linkTweet thisAlerts:
@MstrBobOct 21.2004 — [code=php]





<?PHP
if(substr($_SERVER['SERVER_NAME'], 0, 4)=="www.")
{$domain=substr($_SERVER['SERVER_NAME'], 4);}
else {$domain=$_SERVER['SERVER_NAME'];}
echo($domain);
?>
[/code]
Copy linkTweet thisAlerts:
@dollarguyauthorOct 21.2004 — Wow... thank you so much for the speedy replies...

Will that remove anything before the . - so if someone is opening a page (on their site) which connects to our database... from any virtual host - it will still trim it to just the domain name?

ie: myvirtual.mydomain.com trimmed to mydomain.com

Thanks again.
Copy linkTweet thisAlerts:
@96turnerriOct 21.2004 — //Rewrite of Bobs Code
[code=php]$domain = (substr($_SERVER["SERVER_NAME"], 0, 4) == 'www.') ? substr($_SERVER["SERVER_NAME"], 4):$_SERVER["SERVER_NAME"];
echo $domain;[/code]


//My Code
[code=php]echo strstr($_SERVER["SERVER_NAME"], '.');[/code]
Copy linkTweet thisAlerts:
@dollarguyauthorOct 21.2004 — Here is the code I am using... sorry, cannot seem to integrate your instructions into my page.

$colname_rstMembers = "1";

if (isset($_SERVER['SERVER_NAME'])) {

$colname_rstMembers = (get_magic_quotes_gpc()) ? $_
SERVER['SERVER_NAME'] : addslashes($_SERVER['SERVER_NAME']);

}

mysql_select_db($database_wap, $wap);

$query_rstMembers = sprintf("SELECT * FROM wap_members WHERE mydomain = '%s'", $colname_rstMembers);

$rstMembers = mysql_query($query_rstMembers, $wap) or die(mysql_error());

$row_rstMembers = mysql_fetch_assoc($rstMembers);

$totalRows_rstMembers = mysql_num_rows($rstMembers);

How would I change it to use the domain name as the $colname_rstMembers

Thanks much!!!
Copy linkTweet thisAlerts:
@dollarguyauthorOct 25.2004 — Thanks guy!

I was able to make it work (with your help) - much appreciated.

Daniel
×

Success!

Help @dollarguy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...