Link to home
Start Free TrialLog in
Avatar of jls33fsls
jls33fsls

asked on

Detect # in URL With PHP

I have created a section on my site that has tabs with different content for different pages in them.  I identify them by #id, so that if the user refreshes the page it keeps them on that "id" page instead of going back to the first one.  However, since I switch it over with javascript, it shows the first page for a second while it loads and then switches over to the correct page.  I was wondering if there is a way to do this same thing in PHP.
var the_block = window.location.href.split("#");
		if (the_block[1] == "auctions") {
			document.getElementById('market').style.display = "none";
			document.getElementById('auctions').style.display = "block";
			document.getElementById('market_link2').style.fontWeight = "normal";
			document.getElementById('auctions_link2').style.fontWeight = "bold";
		} else if (the_block[1] == "trades") {
			document.getElementById('market').style.display = "none";
			document.getElementById('trades').style.display = "block";
			document.getElementById('market_link3').style.fontWeight = "normal";
			document.getElementById('trades_link3').style.fontWeight = "bold";
		} else if (the_block[1] == "shop") {
			document.getElementById('market').style.display = "none";
			document.getElementById('shop').style.display = "block";
			document.getElementById('market_link4').style.fontWeight = "normal";
			document.getElementById('shop_link4').style.fontWeight = "bold";
				if (the_block[2] == "stock") {
					click_stock();
					document.getElementById('stock').style.display = "block";
					document.getElementById('inventory').style.display = "none";
					document.getElementById('stock_link').style.fontWeight = "bold";
					document.getElementById('inventory_link').style.fontWeight = "normal";
				} else if (the_block[2] == "history") {
					click_history();
					document.getElementById('history').style.display = "block";
					document.getElementById('inventory').style.display = "none";
					document.getElementById('history_link').style.fontWeight = "bold";
					document.getElementById('inventory_link').style.fontWeight = "normal";
				} else {
					click_inventory();
				}
		}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You may use parse_url() function to get anchor side on a given url as string. You may use ;
<?php
$url = 'http://username:password@hostname/path?arg=value#anchor';

print_r(parse_url($url));

echo parse_url($url, PHP_URL_PATH);
?>
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor

But as hernst42 said you should use JS before...
Avatar of jls33fsls
jls33fsls

ASKER

Well, I thought about doing a cookie, but the problem with this is that if they leave that section and come back it won't go to the first page like they expect.