So you're looking for an explanation of the PHP? I forgot a comparison before and called the wrong variable but that has been corrected here as well. It actually sounds like you aren't looking to redirect the user but are trying to get the contents of another page to display on your page if that is what you are trying to do that is done a different way. Saying you have a js, and html file isn't that helpful because php can work with both of those for instance here if you use method 1 html sends the form to php which processes it to javascript which redirects the user.
PHP Code:
<?php
//If the input field with the name domain is set then process
//http://php.net/manual/en/function.isset.php
if (isset($_POST['domain'])) {
// set the variable $domain to the $_post value
$domain = $_POST['domain'];
//set the required starting characters you want here in this case http://www.
$correct_domain = "http://www.";
//count the number of characters in the required characters variable
$chars_allowed = strlen($correct_domain);
//if the required number of characters of $domain match $correct_domain process
//in other words $domain = http://www.google.com
// this compares the first character "h" through the last according to the number of characters in $correct_domain which is 11 so that ends at "."
// so this would pull out [B]h[/B]ttp://www[B].[/B]
// and then compare it to $correct_domain which is the same so it processes if $domain were https://www. it would not process because the pulled value would be [B]h[/B]ttps://ww[B]w[/B]
if (substr($domain, 0, $chars_allowed)== $correct_domain) {
//here you process your redirect because it was correct
//Method 1, 2, and 3 go in the head. Method 4 needs to be before any html
// Method 1 and 2 are javascript, method 3 is... html? method 4 is php.
//the echos are written so the result is sent to the page once the php is processed. you might have to put methods 1 and 2 into the body tag with the onload not that good at JS the third method goes in the head is uses the meta redirect and the 4th method goes before any html tags it tells the browser what to load.
?>
<script type="text/javascript">
// Method 1: window.open('<?php echo $domain;?>')
//or
//Method 2: window.parent.location="<?php echo $domain;?>";
</script>
<!-- Method 3: <meta http-equiv="refresh" content="0;url=<?php echo $domain;?>" /> -->
<?php
//Method 4: header("Location: $domain");
} else {
//Error, you can handle this however you want
?>
<span style="color:#ff0000;">Please Enter a Valid Domain starting with <?php echo $correct_domain; ?>.</span>
<?php
}
}
?>
<form action="<?php $_SERVER['PHP_SELF']?>" method="post">
<input name="domain" type="text" />
<input type="submit" />
</form>
I guess formatted text doesn't work in commented tags? Can a DD admin/moderator confirm that or verify how to have the bolds show on line 14 of this?
Bookmarks