Jump to content

[SOLVED] extract website address from textbox and redirect to it


jpedrofs

Recommended Posts

Hey guys,

 

I am a beginner trying to figure out how to create a button that redirects you to a website address extracted from a textbox.

 

My attempt goes below:

 

<form method="post" action="<?php $_POST['textbox']; ?>" />

<input type="text" name="textbox" id="textbox" />

<input name="criarblog" type="submit" id="submit" value="submit" />

</form>

 

I haven't managed to put it working.

 

Thanks for any help,

 

Pedro

Hi adam and suttercain,

It is as you say suttercain, the information comes from a textbox that is available in the webpage.

The user introduces an address in the textbox and when the submit button is clicked, there is a redirection to the webpage in the textbox.

Pedro

this may work not 100% sure though

 

<?php
$a= $_POST[‘textbox’];

if(isset($_POST[‘textbox’]))
{
header('Location: $a');
}
else
{
?>
<form action="<?=$_SERVER["PHP_SELF"]?>"...
<input type="text" name="textbox" id="textbox" />
<input name="criarblog" type="submit" id="submit" value="submit" />
</form>
<?php
}
?>

 

 

I just introduced your code suggestion and tried some tweaks, but came back to your original code:

 

<?php

$a= $_POST[‘textbox’];

 

if(isset($_POST[‘textbox’]))

{

header('Location: $a');

}

else

{

?>

<form action="<?=$_SERVER["PHP_SELF"]?>" />

<input type="text" name="textbox" id="textbox" />

<input name="criarblog" type="submit" id="submit" value="submit" />

</form>

<?php

}

?>

change to this

<?php
$a= $_POST[‘textbox’];

if(isset($_POST[‘textbox’]))
{
header('Location: http://$a');
}
else
{
?>
<form action="<?=$_SERVER["PHP_SELF"]?>" />
<input type="text" name="textbox" id="textbox" />
<input name="criarblog" type="submit" id="submit" value="submit" />
</form>
<?php
}
?>

I want to clear something up for jpedrofs.

I can see what you're attemping to do, but your understanding is skewed.

The first time you load your form it looks something like this :

<form method="post" action="" />
<input type="text" name="textbox" id="textbox" />
<input name="criarblog" type="submit" id="submit" value="submit" />
</form>

 

When you click the submit button it will post to the page "" (blank). Now assuming the web browser obliges and guesses that you actually wanted to POST to the same page you are on, you might get lucky, and it'll reload the page you were just on, POST'ing the contents of the textbox to itself. Thus on you 2nd run your form will look something like this :

 

<form method="post" action="whatever-i-typed-in-the-previous-box.com" />
<input type="text" name="textbox" id="textbox" />
<input name="criarblog" type="submit" id="submit" value="submit" />
</form>

 

And on clicking submit again, you'll get lucky and end up on the page you wanted.

 

Have a think about the above, and i'm sure you'll start to see where you were going wrong.

correct way.......

 

<?php
ob_start(); // incase
if($_POST['submit']){
$textbox=$_POST['textbox'];
header("Location: $textbox");
exit;
}
ob_flush(); // incase
?>
<form method="POST" action=" ">
<input type="text" name="textbox" >
<input name="submit" type="submit" value="submit">
</form>

this was fun aswell type http://www.google.com

 

<?php

$x=array('http://www.google.com','http://www.msn.com','http://www.yahho.com');

if($_POST['submit']){

	$url=$_POST['url'];

	if(in_array("$url",$x)){

		echo " congratulations goto <a href='$url'>>>here<<<a/>";
		exit;
	}else{
	echo "sorry we have no $url of this type please try agin <a href='".$_SERVER['PHP_SELF']."'>>>here<<<a/>";
	exit;
	}
     }
          
echo"<center>
<form method='POST' action=' '>
<br><br>
please provide your url <br>
The name off the website<br>
example http://www.google.com!
<br><br>
<input type='text' name='url'>
<br><br>
<input type='submit' name='submit' vlaue='Send'>
</form> 
</center>";

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.