Siddhartha rao Siddhartha rao - 1 month ago 8
PHP Question

Page name as a php variable

I am working on a project that requires me to redirect the user to a php page. And the name of the page to be redirected to is stored as a php variable.This is what I tried. Suppose

$var
is the name of the php file. I want to do something like this,

if(condition)
{
header("Location: '$var'.php");
}


How do I do this?

Answer

You simply need to follow string concatenation here. Try this:

if (condition) {
    header("Location: ".$var.".php"); 
}

Refer to String Operators

Comments