$_GET[] no funciona en el archivo incluido?

I have a webpage which holds the number of the page to display:


This works alright. Now I want to display the page only when a particular cookie is set, and I moved most of the body to an include file, so that index.php only has

    if ($cookie_ok):

y ahora el $_GET["page"] in the include file, which is supposed to retrieve the page number returns nothing.

yo lei eso $_GET[] is a superglobal and that superglobals' scopes are across include files. So what's wrong here, and how can I use the page number in the include file?

preguntado el 28 de mayo de 14 a las 14:05

You're not including another PHP file. You are retrieving the HTML output over your webserver. And this basically remote PHP process won't see the local superglobals. -

2 Respuestas

$_GET works in included archivos, it does not work in included HTTP resources.

The PHP in index_d6skrif9.php será ejecutado por mydomain.net before it gets to the PHP program with the include declaración en él.

Use a local file path, not an HTTP URL.


Alternatively, pass the value to the server you are pulling the include from:

include("http://mydomain.net/index_d6skrif9.php?page=" + urlencode($_GET['page'])); 

Note that the latter approach has far more opportunity for things to go wrong and is much less efficient than a local file included, so it isn't recommended if you can help it.

contestado el 28 de mayo de 14 a las 14:05

You'll need to include them locally, not over-the-web:

if ($cookie_ok) 

By using URLs, you're making a web-request and the server executes the PHP in the file and returns the contents (making it have its own set of super-globals).

contestado el 28 de mayo de 14 a las 14:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.