Jump to content

[SOLVED] PHP $_GET problems


jeff3558

Recommended Posts

I have finally decided to do a little work in PHP (experienced with ASP/ASP.NET )

 

I am having some severe issues with $_GET I have RTFM and Registerglobals is on I am using the latest apache 2 triad as my testing server.

 

here is what is happening...

 

<?php echo $_GET['d'] ;

echo '<br>';

echo $_GET['f'] ;

 

?>

 

<body>

 

<p><a href="tester.php?d=1&f=2">test</a></p>

<p><a href="tester.php?d=2&f=3">test2</a></p>

<p><a href="tester.php?d=3&f=4">test3</a></p>

 

That code works no problem... beginning HTML and end HTML removed just a blank page with 3 links.

 

I am trying to work with a table based page with static top right and bottom with a dynamic content area inside of a table.

in the dynamic area I am trying to use the $_GET to determine which file to include to fill with.

 

echo $_SERVER['REQUEST_URI']; returns what I would expect - /index.php?d=1;f=2

but $_GET will not work, I could band aid this of course and just extract from the URI but I'd like to do this right.

 

Shouldn't matter but I am using Dreamweaver CS3.

The index.php is simple in itself and bare at the moment except for a DHTML menu, which of course has the links i.e. index.php?p=4;f=7

 

I'm convinced this is an idiot problem but I've spent hours trying to chase it down now I'm throwing myself at your mercy.

 

 

Link to comment
Share on other sites

First of all $_GET is not dependent on register globals to work and you should in fact turn register globals off (register globals are completely eliminated in PHP6 and php.net turned them off by default in php4.2 in the year 2002. No new code, tutorials, books... should have been written after then that relied on register globals being on.)

 

However, either something your code is doing is clearing the $_GET values or because register globals are on, they (the $_GET variables) are being overwritten by another variable with the same name $f or $d.

Link to comment
Share on other sites

print_r($_GET); - Returns ARRAY()

 

I went into http://localhost/apache2triadcp and turned the register globals off in the editor (editing C:\windows\php.ini)

 

if(register_globals) {

echo "Register global is ON";}

else{echo "Register global is OFF";}

 

insists it is ON, so again I am at a loss.

 

I cleared my PHP error log and my code is not generating any errors there.

 

I also renamed the variables to pqr and fgn so the were not getting overwritten by anything but that is giving the same results.

There is NO php code at the moment except to check status of register globals and to echo the values nothing has changed though.

 

Do I need to provide anything else?

 

Link to comment
Share on other sites

F:\apache2triad\htdocs\apache2triadcp\.htaccess

 

Require user root

AuthType Basic

AuthName "Apache2TriadCP"

AuthUserFile F:\apache2triad\htdocs\.htpasswd

 

this is not in my site root directory, there was not one there

 

I copied that file to F:\apache2triad\htdocs\

and added

RewriteEngine Off

 

still the same results.

 

 

 

I do at some point want to learn to implement the modrewrite, I know what it does but I would like to get past this very basic step that is kicking my butt at the moment.

 

BYW cooldude your avatar been a long time but is it a nitrogen compound?

Link to comment
Share on other sites

Well I have finally found the problem.

Thanks to all for the help.

Just one more little hump with this I'd like to overcome.

 

I created a file - dynamic_content.php

it is a plain text file no headers of any kind with the contents.

 

print_r($_GET); - Returns Array ( [rp] => 4 [rf] => 7 ) as it should

 

 

<?php

echo $_SERVER['REQUEST_URI'];

echo $_GET['rp'];

echo $_GET['rf'];

?>

 

this does NOT work properly but if I paste the exact same code into the table where I tried to use a SSI it works. I know the SSI was getting processed because it gives the URI but not the $_GET data.

 

Optimally the index.php file should never have to be modified, so what am I missing on that include, does that php script need to have some kind of HTML headers at the top of it?

 

At least I can limp along with what I have for now but I hope one of you know what was happening now.

Link to comment
Share on other sites

Firstly, the purpose of a programming help forum is for people to learn and to help others with the same problem. So please post the solution to the original problem so that someone who finds this thread and has the same symptoms will be able to see if your solution would help him solve his problem.

 

For your current problem, you are obviously doing something in a non-standard way. You would need to post your main file and the file being included, along with their file names/extensions to get any specific help with what it is doing.

 

We need to see the big picture of what you are actually doing in order to be able to help you without playing a game of 20 questions.

Link to comment
Share on other sites

Everything is working properly now I will mark this solved tomorrow night wanted others to see what was going on.

 

To "Firstly" had you read the thread completely you would see that I hadn't really found the PROPER solution just something I could limp along with.

 

I said to begin with this was likely an 'idiot problem' and it was.

 

 

Blank XHTML or PHP file

 

paste in the body :

 

<table width="800" border="1" cellpadding="0" cellspacing="0" id="mainContainer">

  <tr>

    <td>   

    <a href="index.php?t=1">test1</a><br/>

    <a href="index.php?t=2">test2</a><br/>

    <a href="index.php?t=3">test3</a><br/>   

    </td>

  </tr>

</table>

<?php require_once('dyn_content.php'); ?>

<!--#include file="dyn_content1.php" -->

 

 

 

dyn_content.php contains only :

 

<?php

echo $_GET['t'];

?>

 

dyn_content1.php contains only :

 

<?php

echo '<br/>';

echo 'Done the WRONG way';

echo '<br/>';

echo 'Server URI works  -  ';

echo $_SERVER['REQUEST_URI'];

echo '<br/>';

echo '$_GET doesn\'t - ';

echo $_GET['t'];

echo ' - nothing there!';

?>

 

As I said I am new to php but have many years of ASP experience.

I am not sure exactly how the page all gets pieced together here or why the way I was trying to include it did NOT work, it obviously was not an issue of variable scope as the URI had what I needed.

 

Very simple to reproduce yet very frustrating as it seemed like things were working as long as I put the $_GET in the template file and having to modify that file all defeats the purpose of what I am trying to do. I'm trying to idiot proof a companies intranet so when a choice is made from the menu it loads a page created by someone in that department into one of the table cells. In the end the only changes that should ever have to be made would be to the menu.dat file that stores the structure for a DHTML menu's Items and links.

 

Thanks again to all for the fast responses.

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.