Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have:

<?php
$goto = $_GET['goto'];
?>

and:

<form method="get"><input type="text" name="goto" id="goTo" /></form>
<iframe id="page" src="http://<?php echo $goto; ?>"></iframe>

If I go to my page, nothing displays unless I end the URL with ?goto=<webadress>.

Example: http://example.com/windows8/apps/Flake/index.php?goto=http://google.com

How can I make it so that if the user didn't type in ?goto=http://google.com, the page displays like a backup website?

share|improve this question
    
In addition to Jon's answer, you need to add a submit button to your form –  Mohammad Jun 10 '11 at 15:57
add comment

2 Answers

up vote 5 down vote accepted

If you want to provide a default value for $goto, do it like this:

<?php
$goto = !empty($_GET['goto']) ? $_GET['goto'] : 'http://www.google.com'; // default here
?>

However, you should be aware that by doing this, you allow everyone to construct URLs that point to your server but output to the browser HTML (and more importantly, scripts) that is not under your control (it comes from whatever URL goto points to). This would make it trivially easy for someone to attack your users.

share|improve this answer
    
Yeah, I just love this. Answers to stupid questions get most upvotes. We have a problem here, StackExchange! –  Oleh Prypin Jun 10 '11 at 15:54
    
Thank. But I solved it another way! :P I'm making a "web-browser" for my Windows 8 Mimic :) enji.se/windows8 But thnx anyways! :) –  Jeremy Karlsson Jun 10 '11 at 16:03
add comment


$goto = isset($_GET['goto']) ? $_GET['goto'] : "backup page";

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.