I got a small 3 page website. I’m using url rewrite to avoid query strings and it works well, but my contact page needs variables in the url to return any errors. So I am now trying to use regex to capture errors & create variables to echo data back into the form & show errors.
I have done this code below to check url & include the right page which works fine, except when I use contact-us/whatever-I-want-to-capture. Then I get a warning: Warning: include(whatever-I-want-to-capture.php) [function.include]: failed to open stream: No such file or directory
What’s going wrong here?
// include the page according to the url
$url = $_SERVER['REQUEST_URI'];
$url = str_replace (SITE,'',$url);
$contact = preg_match('/contact-us.*/',$url);
if (!$url){
include('home.php');
}
if ($url = $contact){
include('contact-us.php');
}
else { include($url.'.php');
}
You have fallen into the Assignment is not Equality trap.
When assigning a value use =
When testing equality use == (or === in some languages, including PHP)
Hi, thanks for that. I did try using ==, but it still returned the same error. It seems to only work as long as there are no forward slashes in the url.
Ok, I got the url to match contact-us-whatever%20I want but it will only work if I use a - character to separate each capture. Not sure why.
So now I want to capture the data, but I think I’m barking up the wrong tree here. This works so far, but what if the user posts a - character in their email address or their message? That will knacker my contact us script.