0

Very probably this is impossible, but I want to ask it, just in case.

I have a database in which I save some numbers (1, 2, 3...).

I have a .php page from which I read the numbers. I concat those numbers to a string for getting a full URL. For exmaple:

$intArticle = $row["article"];
$strURLBase = "example.com/index.php/"
$strLink = $strURLBase . $intArticle;

//And I get "example.com/index.php/1"

But now, there is an exception in which the URL points to an external website, so my code is not valid for now.

I know how to fix it in .php, but I would like to know if it is possible to make the redirect directly inside the URL, saving the properly string inside the database. For example:

$intArticle = $row["article"];  //In this case, the value of $row["article"] could be, for example, "http://www.externalweb.com"
$strURLBase = "example.com/index.php/"  //This part should be ignore inside the URL
$strLink = $strURLBase . $intArticle;

//I would get "example.com/index.php/http://www.externalweb.com"

Is there any kind of instruction that I could write inside the URL (that I would save into the database and then I would concat to $strURLBase) that redirects to another URL? For example:

example.com/index.php/!$%&_redirec_to("http://www.externalweb.com")

I don't want to call any PHP function from the URL for the redirection. In fact any PHP code shouldn't be executed. Everything should be inside the URL.

  • I guess while concatenation you could check whats there in the intArticle variable. If there is url then use the url itself. If its just a number use your string instead – CodeThing Sep 15 '18 at 10:25
  • Possible duplicate of [Call PHP function from url?](https://stackoverflow.com/questions/4360182/call-php-function-from-url) – Radek Sep 15 '18 at 14:54
  • That script for executing PHP code from the URL is really interesting, but as I have edited in my post, any PHP code shouldn't be executed. Everything should be inside the URL. I'm just asking if it is possible to do or not what I am asking, but it seems that it is not possible... – Alberto Muñoz Sánchez Sep 15 '18 at 15:30

1 Answers1

0

Try this:

if (!is_numeric($intArticle))
{
header("Location: ".$strLink."");
exit;
}
// your site will continue here, if the article is a number
Radek
  • 63
  • 9