Webforumz's RSS FeedRSS Webforumz RegistrationRegister Contact Webforumz StaffContact

PHP form results $PHP_self is blank

This is a discussion on "PHP form results $PHP_self is blank" within the PHP Forum section. This forum, and the thread "PHP form results $PHP_self is blank are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Sep 16th, 2005, 12:55
New Member
Join Date: Sep 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
PHP form results $PHP_self is blank

I'm redesigning my company's website, and I've run across a problem.

I installed PHP on our webserver, and phpinfo shows up just fine! Problem is that when I try to use the page I designed as a feedback form, it fails to get a value for $PHP_SELF. Even when explicitly defined with the complete url (http://thisserver.com/thisisthephpdoc.php) it DOESN'T WORK.

What really sucks is that the form WORKS on my own webserver (which I didn't set up). So it has to be some setting in PHP on this server.

I have the form defined as a variable in the php document itself. Anyway, here's where its called.
Code: Select all
$form ="<div id=\"reg\"><form name=\"form1\" method=\"post\" action=\"$PHP_SELF\">";
When the file is opened in a browser, it shows

Code: Select all
<form name="form1" method="post" action="">
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old Sep 16th, 2005, 17:27
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
try using $_SERVER['PHP_SELF'] instead of just $PHP_SELF
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Sep 17th, 2005, 12:01
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
This is to do with the 'register globals' setting which can be found in your php.ini file. When you want to use a GET, POST or SERVER variable in your PHP page you should really refer to it using it's full name.
Eg: $_SERVER['PHP_SELF']
$_POST['name']

On most servers register_globals this should really be turned off, otherwise someone can send a get variable to your script and, if you haven't declared variables before you use them, override certain sections of your code...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Sep 18th, 2005, 11:23
New Member
Join Date: Sep 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
I tried using the $_server['php_self'] but it gave me a weird parse error.

I made a test page consisting of this:
Code: Select all
<?php

echo($PHP_SELF);
echo($_SERVER['PHP_SELF']);

?>
And it gave me /testing/test.php which is the document and its root. The plain PHP self command still evaluated blank. BUT - seeing that this worked, I put the server php command into my feedback page and got this error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'

Still, shouldn't it work if I explicitly set the file using the FULL http address? Shouldn't that work? It doesnt..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Sep 18th, 2005, 11:25
New Member
Join Date: Sep 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Sirkent
This is to do with the 'register globals' setting which can be found in your php.ini file. When you want to use a GET, POST or SERVER variable in your PHP page you should really refer to it using it's full name.
Eg: $_SERVER['PHP_SELF']
$_POST['name']

On most servers register_globals this should really be turned off, otherwise someone can send a get variable to your script and, if you haven't declared variables before you use them, override certain sections of your code...
Do you mean that Action should be action="$_Post['name']?? What is name supposed to be?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Sep 18th, 2005, 13:10
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
use this code instead of the first line of code you posted in the first post:

Code: Select all
$form ="<div id=\"reg\"><form name=\"form1\" method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">";
and no, you don't use $_POST['name'] in the action attribute of the form tag. $_POST['name'] is used on the page recieving the form data to grab the data from the form. For example, if you have a field called "textfield1", when the data gets sent to the recieving page, you could just reference it with $textfield1, but that is not the correct way to do it, and wont always work - you refer to the variable using $_POST['textfield1'] instead.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Sep 19th, 2005, 10:29
New Member
Join Date: Sep 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Tried the most recent suggestion - same problem:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Sep 19th, 2005, 19:33
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
are you sure that error is the same line of code? because i get no error with the code i gave you...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Sep 19th, 2005, 19:38
New Member
Join Date: Sep 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Its gotta be the server I'm working with. All the code WORKS on my own domain - a server that i didn't set up though, so I don't know how they have their PHP ini file configured.

The annoying part is that it SHOULD work. But its not.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Sep 19th, 2005, 23:26
Tim356's Avatar
Reputable Member
Join Date: Nov 2003
Location: Australia
Age: 26
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
What line number is the error reporting? Can you post that line of code for us?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Sep 21st, 2005, 11:06
New Member
Join Date: Sep 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Here's the page in its entirety on MY webserver, on which it works properly. I know it isn't my code because it works properly on this testing server.

http://www.primitivemelody.us/test/contact.php

On our company's webserver, the file fails to work properly. Here is the EXACT same file on our server, and it won't work.

http://www.gemandjewelry.tv/testing/contact.php

The line of code in question is line 42:
Code: Select all
$form ="<div id=\"reg\"><form name=\"form1\" method=\"post\" action=\"$PHP_SELF\">";
Since it is working on one server and not the other, it has to be an issue with our server. I've tried comparing the PHPInfo readouts, but can't really figure out what differences would cause such an issue! Any ideas?

Thanks so much for all the help so far, btw.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Sep 21st, 2005, 15:08
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
you still need to change that line to

Code: Select all
$form ="<div id=\"reg\"><form name=\"form1\" method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">";
it may be that the two different servers are running two different versions of PHP, and it's likely that the php.ini files are configured differently.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Sep 21st, 2005, 16:31
New Member
Join Date: Sep 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by benbacardi
it may be that the two different servers are running two different versions of PHP, and it's likely that the php.ini files are configured differently.
Well I initially installed the same version of PHP on our server that is on mine, but upgraded hoping it might solve the issue. Is there any way to see how their PHP ini file is configured and match it to ours??

The only other thing I can think of is that possibly the mail() command settings in the PHP.ini file aren't right (I have them set to send mail through our gmail account), but that wouldn't make something like that not work properly, would it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Sep 22nd, 2005, 07:20
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Have a look at a PHPInfo screen:

Code: Select all
<?
phpinfo();
?>
It'll give you useful information that may help you track this down.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Sep 22nd, 2005, 08:24
Tim356's Avatar
Reputable Member
Join Date: Nov 2003
Location: Australia
Age: 26
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
I think he's tried that one, but yeah - comparing the .ini files would be the same as comparing the phpinfo pages.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16