How to modify URL based on user input?

liunx

Guest
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. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/blink.gif" style="vertical-align:middle" emoid=":blink:" border="0" alt="blink.gif" /> <br /><br />Here's the scenario:<br /><br />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: <u>http://cgi.ebay.com/ws/eBayISAPI.dll?ViewI...xxxxxxxxxxxxxx</u>.<br /><br />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 <u>http://cgi.ebay.com/<!--coloro:#3333FF--><span style="color:#3333FF"><!--/coloro-->textbyuser<!--colorc--></span><!--/colorc--></u>.<br /><br />I'm just wondering if this is even possible.<br /><br />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).<br /><br />Thank you.<!--content-->
Do you mean like what these sites provide?<br /><br /><a href="http://www.shorturl.com/" target="_blank">http://www.shorturl.com/</a><br /><a href="http://notlong.com/links/" target="_blank">http://notlong.com/links/</a><!--content-->
<!--quoteo(post=156458:date=Nov 23 2005, 05:36 PM:name=TheCanadian)--><div class='quotetop'>QUOTE(TheCanadian @ Nov 23 2005, 05:36 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=156458"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->Do you mean like what these sites provide?<br /><br /><a href="http://www.shorturl.com/" target="_blank">http://www.shorturl.com/</a><br /><a href="http://notlong.com/links/" target="_blank">http://notlong.com/links/</a><!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />No but thanks for replying.<!--content-->
I thought that may have been the end result of what you were trying to do.<br /><br />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"?<br /><br />Javascript would be the simplest I would think. Something like this:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><html><br /><head><br /><title>Custom Redirect Script</title><br /><script type="text/javascript"><!--<br />function gohere() {<br />    var url="http://www.testing.com/";<br />    var addon=document.getElementById('AddMe').value;<br />    location.href=http://www.totalchoicehosting.com/forums/lofiversion/index.php/url+addon;<br />}<br />//--></script><br /></head><br /><body><br /><form><input type="text" id="AddMe" size=50><input type="button" value="Go!" onClick="gohere();"></form><br /></body><br /></html><!--c2--></div><!--ec2--><br /><br />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?)<!--content-->
I found a site that does basically what I'm looking for:<br /><br /><!--coloro:blue--><span style="color:blue"><!--/coloro-->LINK REMOVED!!! DON'T LINK TO OTHER WEBHOSTS IN THIS FORUM<!--colorc--></span><!--/colorc--><br /><br />At the above site, a user enters a <i>username</i> which in turn becomes a webpage.<br /><br />So it is possible...any idea how they accomplished this?<br /><br />Thanks.<!--content-->
Hi rnmcd,<br /><br />When you are using PHP, and you submit a form, any input items within that form are passed to the target page as variables.<br /><br />So if you have the following code:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><form name="myForm" method="get" action="somepage.php"><br /><input type="text" name="UserID" size="15" maxlength="15"><br /><input type="submit" name="submit" value="Login"></form><!--c2--></div><!--ec2--><br /><br />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<br /><br />That information is shown in the URL because you used the method="get" attribute in the form tag. <br /><br />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).<br /><br />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:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><form name="myForm" method="post" action="somepage.php"><br /><input type="text" name="UserID" size="15" maxlength="15"><br /><input type="submit" name="submit" value="Login"></form><!--c2--></div><!--ec2--><br /><br />This does basically the same thing, but it doesn't append the variables to the URL.<br /><br />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).<br /><br />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.<br /><br />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.<br /><br />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.<br /><br />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.<br /><br />I hope that was what you were asking.... If you need more help, let me know.<br /><br /><br />When the user enters data into the UserID text field and clicks the Login button, they will be redirected to "somepage.php?UserID<!--content-->
abinidi, thanks for the great help!<br /><br />Very nice portfolio too!<br /><br /><br /><!--content-->
Glad you found the information useful.<br /><br /><br />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. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><br /><br />Good luck with your project.<!--content-->
 
Top