Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using # and ? in a URL 1

Status
Not open for further replies.

gfender

IS-IT--Management
May 22, 2003
55
GB
I wasn't quite sure how to put this because I don't know the technical names for these two things otherwise I could find them on google. Basically I am trying to access a variable from the url using. The link is like the following:
Code:
[URL unfurl="true"]http://www.mydomain.com/mypage.php#id=35?action=go[/URL]
I tried accessing the variable using PHP but it didn't pick it up. Is my syntax right for doing this?

Thanks a lot.
Gabe
 
Almost right... use a ? to seperate the url:
Code:
[URL unfurl="true"]http://www.mydomain.com/mypage.php?id=35&action=go[/URL]
Now... that URL above will provide you 2 variables that are available from PHP using:
Code:
<?
echo "id=" . $_GET['id'];
echo "action=" . $_GET['action'];
?>
You might use the # in place of the ? when you are requesting an anchor on the page... but that is something completely different.

Hope that helps (I'm still learning myself) [smile]
Jeff
 
Oh sorry, I forgot to mention that I did in fact want an anchor for the id so I do need to have a #. Thanks for responding so quickly.
 

In which case... what variable are attempting to read? Using the url you posted would allow you to query the action variable (but not the id variable). If you wanted to get access to the id (based on the anchor marker) then you would have to query the url directly.

I haven't got the ability to tets this, but I think this will echo your URL... from there it will just be a case of string manipulation.

Code:
echo $_SERVER["PHP_SELF"];

Cheers,
Jeff

 
I am attemping to read the 'action' variable using $_GET['action'] while still keeping the anchor tag in tact. So the page will go to the anchor yet still be able to access the 'id' variable in the url.
 
gfender-
I made this small php file to test....
Code:
<html>
<head>
<title>e</title>
</head>
<body style="margin:0px">
<form name="t" action="anctest.php#two">
	<input value="joe" name="name" />
	<input value="5" name="id" />
	<input type="submit" />	
</form>
<?php
for ($i=0; $i<100; $i++)
echo "<br />";
?>
<hr noshade="noshade" />
<a name="two">two!</a>
<?php
for ($i=0; $i<100; $i++)
echo "<br />";
?>
</body>
</html>

The result (on a submit) is something like this:
anctest.php?name=joe&id=5#two

test it out if you wish. name the file anctest.php or change the form action to direct it at the correct place.

Robert Carpenter
"You and I have need of the strongest spell that can be found to wake us from the evil enchantment of worldliness." - C.S. Lewis (The Weight of Glory)

 
Thank you, I guess it was as simple as just reversing what I had in the beginning.
 
;-)

you are welcome

Robert Carpenter
"You and I have need of the strongest spell that can be found to wake us from the evil enchantment of worldliness." - C.S. Lewis (The Weight of Glory)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top