PHP get current URL

Questions about programming languages and debugging
Post Reply
User avatar
sternbildchen
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 421
Joined: 26 Apr 2006, 16:00
17
Location: Germany

PHP get current URL

Post by sternbildchen »

Code: Select all

<li <?php if(is_home()) { echo 'class="current_page_item"';} ?>><a href="<?php bloginfo('siteurl'); ?>">Blog</a></li>
This is my current code. Now I need a second code to replace is_home() . Here what it should do:

if ("current url" starts with http://localhost/wp02/index.php/2007) {}

It should also return true if the url is something like http://localhost/wp02/index.php/2007/07/

I hope someone can help me. I just can't find something that works.

Thanks guys!

shamir
Computer Manager
Computer Manager
Posts: 853
Joined: 01 Mar 2007, 17:00
17
Location: NY
Contact:

Post by shamir »


pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Post by pseudo_opcode »

Code: Select all

if(strpos('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],$url_you_want)==0)
$url_you_want is the url you want to compare with

have fun

User avatar
sternbildchen
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 421
Joined: 26 Apr 2006, 16:00
17
Location: Germany

Post by sternbildchen »

Thanks pseudo this is what I was searching for!

The bad thing is that it doesn't seem to work for me. Maybe because the server is local? I don't know :wink:
if(strpos('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],'http://localhost/wp02/index.php/2007/')==0)
always returns true
(f.e. on http://localhost/wp02/)

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Post by pseudo_opcode »

try this

Code: Select all

if(stripos('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],'http://localhost/wp02/index.php/2007/'))
notice the new function "stripos" and there's no "==0" there,

which version of php you using?

User avatar
sternbildchen
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 421
Joined: 26 Apr 2006, 16:00
17
Location: Germany

Post by sternbildchen »

PHP Version 5.2.0

I will test out the new code tomorrow. But I will be on vacation for the text three weeks. Thanks for your help! If the code doesn't work I will write something here in three weeks.

/edit: Still doesn't work. Now it always returns false.

Post Reply