0

I need to fix this URL redirect in header

$siteurl = http://myfirstsite.com
$siteurl2 = http://mysecondsite.com

<a href="<?php echo if (strstr ($_SERVER["REQUEST_URI"], "hus")) {
    echo $siteurl;
} else {
    echo $siteurl2;
}."/".ereg_replace(" ", "-", $show_wallpaper["caturl"])."-".$show_wallpaper["categoryid"]."-"."1.php"; ?>">

It throws an error now.

2 Answers 2

2

You are concatenating against the braces of an if block {}. Instead, echo:

<a href="<?php echo if (strstr ($_SERVER["REQUEST_URI"], "hus")) {
    echo $siteurl;
} else {
    echo $siteurl2;
}
echo "/".ereg_replace(" ", "-", $show_wallpaper["caturl"])."-".$show_wallpaper["categoryid"]."-"."1.php"; 
?>">
Sign up to request clarification or add additional context in comments.

Comments

0

First off, don't use ereg functions. They're deprecated. Use the preg functions instead.

preg_replace('/ /', '-', ...);

Beyond that, the fix is trivial:

if (...) {
   header('Location: ' . $siteurl . preg_replace(...));
} else {
   header('Location: ' . $siteurl2 . preg_replace(...));
}

2 Comments

i use like this <a href="<?php if (strstr ($_SERVER["REQUEST_URI"], "hus")) { header('Location: ' . $siteurl . preg_replace(" ", "-", $show_wallpaper["caturl"])."-".$show_wallpaper["categoryid"]."-"."1.php")); } else { header('Location: ' . $siteurl2 . preg_replace(" ", "-", $show_wallpaper["caturl"])."-".$show_wallpaper["categoryid"]."-"."1.php")); } ?>">
preg requires delimiters around the regex. '/ /', not " " as you have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.