heron
heron

Reputation: 3661

How to get clean website url with php?

I'm using $wsurl as my websites clean url $wsurl = 'http://'. $_SERVER['HTTP_HOST'] . '/'; But recently when I want to echo it from websites admin panel it gave me result:

http://localhost/admin/>http://localhost/?page=166

instead of

http://localhost/?page=166

More Detailed

What i use: <a target="_blank" href="><?=$wsurl?>?page=<?=$new_id?>">Link</a>

What i get as html output <a target="_blank" href=">localhost/?page=170">Link</a>

But when i click it from admin panel, it opens page localhost/admin>http://localhost/?page=170 (instead of http://localhost/?page=170) which doesn't exist at all

How to deal with that problem?

I want to get websites main url from everywhere within ws. For ex, if i'm in admin panel http://localhost/admin/index.php the $wsurl will be http://localhost/

If my admin panels url looks like http://mydomain.com/admin/index.php the $wsurl will be http://mydomain.com/

Upvotes: 0

Views: 8461

Answers (1)

aNi
aNi

Reputation: 1359

If you are facing issues like that then you can try this :

$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 
echo 'http://'.parse_url($url, PHP_URL_HOST) . '/';

Upvotes: 4

Related Questions