Jump to content

$_get is not retrieving my variable from the URL


Recommended Posts

my "$_get" function is not retrieving the "id" variable from the URL (".../index.php?id=1")

 

I have no clue why it isn't "getting" the variable. I don't get any error messages from the server and I've tried to echo the variable and it just won't read "id" from the URL

 

<?php
$article = $_GET['id'];
if ($article == 1) {
include 'article1.php';
}
elseif ($article == 2) {
include 'article2.php';
}
elseif ($article == 3) {
include 'article3.php';
}
elseif ($article == 4) {
include 'article4.php';
}
else {
include 'no_article.php';
}
?>

Link to comment
Share on other sites

djfox: It's on my server  ;)

 

kenrbnsn: I uploaded the code you gave me and then visited the page THAT INCLUDES THE SCRIPT and it had empty parentheses. I put those words in caps because the script is included on my website, not in the "index.php" file itself. I think this has something to do with it because when i point my browser to the actual script with the "id" variable in the URL it prints:

Array
(
    [id] => 7
)

Link to comment
Share on other sites

script is included on my website

 

Maybe if you show your actual full code involved in the problem someone could directly solve this. xxxxx out any information you don't want to post, such as your domain name, but don't change any of the syntax (such as if you are using a URL to include the file http://xxxxx.com/file.php or using a file system path.)

Link to comment
Share on other sites

I knew using a URL was probably it.

 

When you post part of your code out of context of how it is actually being used and you tell us that 'this is my code and it is not working', but in reality that is not all your actual code that is involved in the problem, it takes a really long time to help you, in this case ~20hours.

 

When you use a URL in an include, it causes your web server to make a http request back to your web server. This invokes a separate instance/child process of your web server/php to parse the requested file. This causes several things to happen -

 

1) It takes a minimum of 100 times longer than if you used a directly file system path,

2) The included file does not inherit the variable scope of the main file (which is why you are getting the symptoms that you are),

3) You only get back the content that is output by that file, you don't get the php code and data from that file incorporated into the main file, and

4) The settings that allow this might not be enabled on any particular server configuration, so you might find your include statement not working at all (and not just the variables) if you move to a different server or someone updates/alters the configuration of your existing server.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.