[Resolved] Current Page Url Variable???

Namecheap AuctionsNamecheap Auctions
NamecheapNamecheap
SpaceshipSpaceship
Watch

dkin69

Established Member
Impact
4
Current Page Url Variable???

Ok this is my problem.

I have a script I am using as an include in many sites. It pulls info from a database and displays ads. Now every site that this is displayed on has an ad in the database and I dont want anyones ads showing on their own site.

I wrote this.

##$current = $_SERVER["HTTP_HOST"];
$current = $_SERVER['PHP_SELF'];

$lin = mysql_query("SELECT * FROM link order by id asc", $link) or die ("query 1: " . mysql_error());
echo '<li><h2>LinkWork</h2>'
. '<ul>';
while ($li = mysql_fetch_array($lin)) {
if ($current == $li['base'])
{
echo '';
}
else
{
echo '<li><a href="'.$li['web_url'].'" alt="'.$li['alt_tag'].'">'.$li['display'].'</a></li>';

}
}

The column base, is the base of a url eg. digitalpoint.com

So that is what I need to find, a php variable that gives me the current pages web address, but only up to the end of the com or org.
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Something like this?

$domain = str_replace("www." ,"", $_SERVER['SERVER_NAME']);

$lin = mysql_query("SELECT * FROM link WHERE base = '" .$domain ."' order by id asc", $link)
 
0
Close
PHP:
$url =  $_SERVER['SCRIPT_URI'];
$parsed_url = parse_url($url);
$domain = $parsed_url['hostname'];

at this point, $domain should be whatever the domain portion is.

To see more information about the PHP parse_url() function, go here: http://us2.php.net/parse_url
 
0
Close
ok, I had to alter my code, it is now this

Include.php

$lin = mysql_query("SELECT * FROM link order by id asc", $link) or die ("query 1: " . mysql_error());
echo '<li><h2>LinkWork</h2>'
. '<ul>';
while ($li = mysql_fetch_array($lin)) {
if ($current == $li['base'])
{
echo '';
}
else
{
echo '<li><a href="'.$li['web_url'].'" alt="'.$li['alt_tag'].'">'.$li['display'].'</a></li>';

}
}

Including file

<?php
$current = 'bluewidget';
include("include.php");?>

This is on a wordpress blog if that helps.

and the variable in the including file just doesn't seem to be being set.

I also tested it.

I inserted this into my page
$numfive = 5;

I inserted this into my include

$numfour = 4;
$done = $numfour + $numfive;

when the page is called it returns "4"

any ideas?
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back