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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use cookie to builds a URL

Status
Not open for further replies.

acelink

Technical User
Oct 12, 2006
2
CA
Is it possible to use a cookie to build a url?
I have members place an 8 digit field in a form and then use that string to build a URL and also reuse the cookie value on other pages.
Example user enters 10010002 in the form input field.
Can I then save that to a cookie called path and redirect the user to I would also like to be able to use that cookie as a varible in other pages such as <a href= etc.
I have no experience with Javascript so any help would be appreciated.
 
this seems to be quite simple, however you would need to think about what would happen if the cookie is not there or the user does not have Javascript enabled ? Additionally you may have to consider what happens if I change the value I have (e.g. 10010002 to say 10010003) do I see something I should not ?

You may be better off doing this server side where you have more control and use a URL like :

<a href= >PRODUCTS</A>


Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005
 
I am using htaccess to limit the directory so the 10160001 is actually the directory that is protected by htacccess. I am would like to use the cookie to recall the directory to use in building urls within the html pages dynamically instead of hard coding the url for each member.
I when enterin gthe site I check for cookies turned on and if they are not htey are redirected back to the main public website and not allowed to enter.
Also I would be setting the cookie not the user.
i do not have access to php.
thanks
 
try something like :

function buildURL()
{
// get the cookie value
var accountKey=getCookie("accountkey");

// build the URL
var URL=" + accountKey + "/products.html";

// redirect
document.location=URL;
}

<a href="javascript:buildURL()">Product</a>

This is a very simple sample script, I've left out the getCookie function as there are many on the web that will do this.

Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top