• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

PHP Help needed!

Boreded

New Member
how do i get a new window to open with the URL a user types in a form, for example if you were to type a website address into a box it will open that address in a new window.
its hard to explain what i need this for, but anyone know how to do this?
 
Tree, that's not what he wanted. But anyway, you can use the following code.

Form Code:
HTML:
<form action="redirect.php" method="GET" target="blank">
<input type="text" name="url">
<input type="submit" value="Go">
</form>

redirect.php Code:
PHP:
<?php
header("Location: ".$_GET['url']);
?>

I haven't tested it but it should work.
 
So you can change three letters and add a fourth one. Not too hard. GET is good for passing small amounts of non-sensitive data. Anything more than that should be used with POST.
 
^^ nope, not even a litle bit, they are both server globals, they are both for retrieving information from the server, the get method reads a pre-formatted url to read variables, when you use the post method the information is hidden and posted straight to the apache processes cache, php / cgi /rails / asp or whatever reads this information and deciphers variables in the same way as get, only hidden from sight.
 
Depends what you want to transmit, if you just want to tell the webserver which page of a search you want then you might use script.php?page=1 however if on page one you had to login it wouldn't be a good idea to have the username and password in the url and so you would use the post method to hide these variables, generally any data that is large (+5 chars) or sensitive at any level you would post, anything else it's safe to use get.

On both methods, it's always a good idea to sanitize the characters with stripslashes(trim($_POST['var'])) <-- same for get, also if the data is ever used for a mysql_query statement then make sure you use mysql_real_escape_strim( stripslashes( trim( $var ) ) ) or similar, look it up...

Also, try to check for instance if you expect a form to post numers, that the posted variable is numbers, or vice versa..
 
Back
Top