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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
}
?>

 

 

Link to comment
Share on other sites

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

}

?>

Link to comment
Share on other sites

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
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>";

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.