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

Simple build URL question

Reply to Message Icon

Original Message
Name: jsruzicka
Date: January 31, 2007 at 12:18:37 Pacific
Subject: Simple build URL question
OS: NA
CPU/Ram: NA
Model/Manufacturer: 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


Report Offensive Message For Removal


Response Number 1
Name: Taurus
Date: January 31, 2007 at 17:10:16 Pacific
Subject: Simple build URL question
Reply: (edit)

(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.


Report Offensive Follow Up For Removal

Response Number 2
Name: Taurus
Date: January 31, 2007 at 17:14:00 Pacific
Subject: Simple build URL question
Reply: (edit)

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.


Report Offensive Follow Up For Removal

Response Number 3
Name: Taurus
Date: January 31, 2007 at 17:15:53 Pacific
Subject: Simple build URL question
Reply: (edit)

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.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Simple build URL question

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge