开发者

How do I Create a Unique PHP Landing Page when incorrect values are passed via GET?

I have a URL that is passed incorrect values when loaded and since the script has a PHP template backing the link I don't get a 404 error. Here is my example:

http://www.examplesite.com/template.php?value=incorrect

As you can see, the "template.php" page will load, but all of the info that is linked to this page via a database table is empty due to the "incorrect" value that are being passed. Now for my question.

I would like this to be redirected to a unique landing page when an incorrect value is passed in this manner rather than having the page load with empty value开发者_JAVA技巧s. Is this possible? If so, how?


You could make a check and redirect user to your landing page if the value passed via GET is incorrect.

  • Filter your GET variable.
  • Make a database query.
  • Check the result of query if it is null redirect users to landing page.
   if($db_value == null)
   {
     header('location:http://www.example.com/landingpage');
     die();
   }


Use http_redirect as documented here, but read the documentation carefully, you must issue the redirect before any other output is written.


You should have the following code as the first line of your script (in template.php):

<?php
$value = $_GET['value'];

$sql = "SELECT count(*) FROM tblName WHERE col1 = '$value'";
$rs = mysql_fetch_assoc(mysql_query($sql, $dbCONN));

if ($rs[0] == 0) {
    header("Location: /page-not-found.php");
} else {
    <process your actual code>
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜