Computing.Net > Forums > Web Development > Simple build URL question

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Simple build URL question

Reply to Message Icon

Name: jsruzicka
Date: January 31, 2007 at 12:18:37 Pacific
OS: NA
CPU/Ram: NA
Product: NA
Comment:

How do, simply, build a URL link that requires a portion of it to contain input from the user. For example (with spaces removed obviously)

http // mailservername. <<mailfilename>> .blahblah

The URL will always be the same except <<mailfilename>> will change and be input by the viewer of the page. Is this an easy thing to do?

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Taurus
Date: January 31, 2007 at 17:10:16 Pacific
Reply:

(I'm going to show this in PHP)

Ok im understanding it as the user inputs a filename and the page either outputs the text of the link or goes directly to that link.

INPUT PAGE (only partial code and just the HTML)
<form method="post" action="url_script.php">
<input type="text" name="url" size="20" />
<input type="submit" value="Submit" />
</form>

SCRIPT 1 (Redirect)
<?php
$url = $_POST['url'];
header("Location: http://mailservername" . $url . "blahblah");
?>

SCRIPT 2 (Output/Print)
<?php
$url = $_POST['url'];
echo 'Link';
?>

That what your looking for? Don't forget to add some security to these scripts, such as filtering the input etc...

Developers have a sense of humour, it's just commented out.


0

Response Number 2
Name: Taurus
Date: January 31, 2007 at 17:14:00 Pacific
Reply:

Sorry forgot to add that if spaces are used in the input, you should use a function to remove spaces from the input. This function should do the job nicely. Good luck.

function remove_spaces($text)
{
$text_len = strlen($text);

$fixed_text = "";
for($i=0;$i<$text_len;$i++)
{
if(substr($text,$i,1) != " ")
{
$fixed_text = $fixed_text . substr($text,$i,1);
}
}

return $fixed_text;
}
return $fixed_text;
}
?>

Developers have a sense of humour, it's just commented out.


0

Response Number 3
Name: Taurus
Date: January 31, 2007 at 17:15:53 Pacific
Reply:

I really should plan a post before I dig into it. If you need to replace the spaces with %20 then here is a function to do that also.

function replace_spaces($text)
{
$text_len = strlen($text);

$fixed_text = "";
for($i=0;$i<$text_len;$i++)
{
if(substr($text,$i,1) == " ")
{
$fixed_text = $fixed_text . "%20";
}
else
{
$fixed_text = $fixed_text . substr($text,$i,1);
}
}

return $fixed_text;
}

Developers have a sense of humour, it's just commented out.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Simple build URL question

returning values with AJAX www.computing.net/answers/webdevel/returning-values-with-ajax/3205.html

Date pop-up box in ASP.NET www.computing.net/answers/webdevel/date-popup-box-in-aspnet/833.html

XML question www.computing.net/answers/webdevel/xml-question/2366.html