rnmcd Posted November 23, 2005 Posted November 23, 2005 (edited) Reading this post should afford the majority of the folks here a great deal of entertainment since I don't know enough to ask my question properly. Here's the scenario: On a website that generates a new page and a long URL from a user-action (for example, when a new auction is created on ebay you get a long URL like: http://cgi.ebay.com/ws/eBayISAPI.dll?ViewI...xxxxxxxxxxxxxx'>http://cgi.ebay.com/ws/eBayISAPI.dll?ViewI...xxxxxxxxxxxxxx. Is there a way to create a user-completed form on the website whereas the text entered into that form could rewrite the URL? In other words, the user-entered text would create a new, shorter URL such as http://cgi.ebay.com/textbyuser. I'm just wondering if this is even possible. If you happen to know of websites that do this please post the URL. I really think I saw it somewere a while back but I can't recall the domain(s). Thank you. Edited November 23, 2005 by rnmcd Quote
TheCanadian Posted November 23, 2005 Posted November 23, 2005 Do you mean like what these sites provide? http://www.shorturl.com/ http://notlong.com/links/ Quote
rnmcd Posted November 24, 2005 Author Posted November 24, 2005 Do you mean like what these sites provide? http://www.shorturl.com/ http://notlong.com/links/ No but thanks for replying. Quote
TheCanadian Posted November 24, 2005 Posted November 24, 2005 (edited) I thought that may have been the end result of what you were trying to do. So you would want a scrpt that would take something entered by a user, tag in onto the end of a predefined URL, then go to that URL... So if for example they would enter "images/header.jpg", and your default URL was "http://www.testing.com/", the browser would then go to "http://www.testing.com/images/header.jpg"? Javascript would be the simplest I would think. Something like this: ><html> <head> <title>Custom Redirect Script</title> <script type="text/javascript"><!-- function gohere() { var url="http://www.testing.com/"; var addon=document.getElementById('AddMe').value; location.href=url+addon; } //--></script> </head> <body> <form><input type="text" id="AddMe" size=50><input type="button" value="Go!" onClick="gohere();"></form> </body> </html> There's probably a neater way of doing that, but off the top of my head it's the simplest thing I could think of that does what I mentioned above (assuming that is what you are after?) Edited November 24, 2005 by TheCanadian Quote
rnmcd Posted November 25, 2005 Author Posted November 25, 2005 (edited) I found a site that does basically what I'm looking for: LINK REMOVED!!! DON'T LINK TO OTHER WEBHOSTS IN THIS FORUM At the above site, a user enters a username which in turn becomes a webpage. So it is possible...any idea how they accomplished this? Thanks. Edited November 25, 2005 by TCH-Bruce Quote
abinidi Posted December 22, 2005 Posted December 22, 2005 (edited) Hi rnmcd, When you are using PHP, and you submit a form, any input items within that form are passed to the target page as variables. So if you have the following code: ><form name="myForm" method="get" action="somepage.php"> <input type="text" name="UserID" size="15" maxlength="15"> <input type="submit" name="submit" value="Login"></form> Lets say a user comes to the page, and enters their UserID into the form. If they enter 12345, and click submit, they will be redirected to somepage.php?UserID=12345 That information is shown in the URL because you used the method="get" attribute in the form tag. Now, on the page somepage.php the UserID variable is ready to use, and has the value 12345 (or whatever the user entered on the previous page). But maybe you don't want to pass the UserID in the URL (for security reasons). Then you could use the method="post" attribute in the form tag, like this: ><form name="myForm" method="post" action="somepage.php"> <input type="text" name="UserID" size="15" maxlength="15"> <input type="submit" name="submit" value="Login"></form> This does basically the same thing, but it doesn't append the variables to the URL. So if a user came to the page and entered 45678 into the text box, and clicked the submit button, they would be redirected to somepage.php (notice the lack of the ? and variables after the file name). But the great thing is, the variables are still passed to somepage.php, and you can use them on somepage.php for whatever you need. So you can use the POST method, or the GET method to pass form input from one page to another as a PHP variable. If you use the POST method, then the variables aren't placed in the URL. If you use the GET method, the variables are placed in the URL. Be careful with the GET method, though, because I believe there is a finite limit to the size of a URL. So if you have a user who enters a blog post, you wouldn't want to pass that with the GET method, because it would be way to long. However, if you are passing a session ID or something, and you want users to have a unique URL, then you can use the GET method. Recently I was designing a web application for my wife's thesis. Users logged in and were assigned to a specific treatment. I passed the treatment variable with the GET method to all the URLs so I could have IF/THEN php statements to determine what to do on each page, based on the users treatment. I could have used the POST method, but I liked being able to see the variable in the URL because then I knew it was being passed correctly from page to page. It was my first php project, so that helped me find my errors. I hope that was what you were asking.... If you need more help, let me know. When the user enters data into the UserID text field and clicks the Login button, they will be redirected to "somepage.php?UserID Edited December 22, 2005 by abinidi Quote
rnmcd Posted August 9, 2007 Author Posted August 9, 2007 abinidi, thanks for the great help! Very nice portfolio too! Quote
abinidi Posted August 9, 2007 Posted August 9, 2007 Glad you found the information useful. Sorry about the last line of that post. I must have left it when I was editing the post and forgot to erase it. Now it is WAY too lat to edit the post. Good luck with your project. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.