How to access a website's url programmatically from within the page
For work, I am working on a site that has a feature that lets users make custom instances of the site depending on who they want to show it to. So if they want to show their potential employer a little bit about themselves, they can send them a custom url, that has a uid on the end of it that tel开发者_如何学Gols the database what to show and what not to when the site is loaded up.
Now, I need to be able to take the value that is on the end of the url, this unique uid that corresponds with their preferences in the db, accessable on run time. Meaning that when someone types in this custom url, I need to be able to show the name of the person whose portfolio is being viewed BEFORE password authentication takes place...
If I could get the URL, I suppose I could parse through it to find the necessary UID...but how do I get the url? Maybe I am just missing something here, but if anyone has any thoughts or ideas, it would be appreciated!! Thanks
Sorry, to further clarify, I am using PHP to handle calls to the database...
Did you know dynamic web site technologies do just that? There are lots of them and it is fairly easy to get the parameters from the URL.
Examples :
PHP: http://www.example.com/show.php?uid=123
$_GET['uid'];
JSP: http://www.example.com/show.jsp?uid=123
request.getParameter("uid");
There are so many of them it's pointless to enumerate them here
If you are using a server-side language, you can get any part of the url easily, for example, in php, it can be gotten through $_GET
array and other arrays. If you want it with javascript, you can do like:
JS Example:
var url_array = document.location.href.split('/');
echo url_array[0]; // part one
echo url_array[1]; // part two
echo url_array[2]; // part three
You can even get the host part with:
alert(document.location.host);
PHP Example:
www.mysite.com?id=100
echo $_GET['id'];
This would depend on what language you are using, but typically that uid at the end of the URL would be passed as a request parameter, like this:
www.mysite.com/info?uid=dkafdojoapjdopakd
You would then access it in your code using the request parameters. So, in PHP, it would be:
$uid = $_GET['uid'];
// get the appropriate data for this uid, write out the page contents, etc.
First store each user's preferences as a piece of css within html style tags
+-----------+---------------+
| UID | style |
+-----------+---------------+
| 0z65dbr | <style>h1{ |
| | font-family: |
| | arial, |
| | sans-serif |
| | }</style> |
+-----------+---------------+
Then setting the get variable 'uid' in the url eg. www.example.com/page?uid=0z65dbr you can extract the value form the uid variable in php with $_GET['uid']
and pass this value to your sql query:
$sql = "SELECT style FROM styles WHERE UID = '".mysql_real_escape_string($_GET['uid'])."'";
Then in the put the result of executing the query into the head section of the html.
精彩评论