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.



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

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Sep 16th, 2005, 11: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="">
Reply With Quote

  #2 (permalink)  
Old Sep 16th, 2005, 16: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
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
try using $_SERVER['PHP_SELF'] instead of just $PHP_SELF
Reply With Quote
  #3 (permalink)  
Old Sep 17th, 2005, 11: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...
Reply With Quote
  #4 (permalink)  
Old Sep 18th, 2005, 10: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..
Reply With Quote
  #5 (permalink)  
Old Sep 18th, 2005, 10: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?
Reply With Quote
  #6 (permalink)  
Old Sep 18th, 2005, 12: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
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
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.
Reply With Quote
  #7 (permalink)  
Old Sep 19th, 2005, 09: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'
Reply With Quote
  #8 (permalink)  
Old Sep 19th, 2005, 18: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
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
are you sure that error is the same line of code? because i get no error with the code i gave you...
Reply With Quote
  #9 (permalink)  
Old Sep 19th, 2005, 18: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.
Reply With Quote
  #10 (permalink)  
Old Sep 19th, 2005, 22:26
Tim356's Avatar
Reputable Member
Join Date: Nov 2003
Location: Australia
Age: 25
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tim356
What line number is the error reporting? Can you post that line of code for us?
Reply With Quote
  #11 (permalink)  
Old Sep 21st, 2005, 10: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.
Reply With Quote
  #12 (permalink)  
Old Sep 21st, 2005, 14: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
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
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.
Reply With Quote
  #13 (permalink)  
Old Sep 21st, 2005, 15: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?
Reply With Quote
  #14 (permalink)  
Old Sep 22nd, 2005, 06: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.
Reply With Quote
  #15 (permalink)  
Old Sep 22nd, 2005, 07:24
Tim356's Avatar
Reputable Member
Join Date: Nov 2003
Location: Australia
Age: 25
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tim356
I think he's tried that one, but yeah - comparing the .ini files would be the same as comparing the phpinfo pages.
Reply With Quote
  #16 (permalink)  
Old Sep 23rd, 2005, 10:34
New Member
Join Date: Sep 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Y'all are going to hate me.

Now, using the concactenated version of $_Server['php_self'] and turning on error readouts, it at least gets through the action part of the form and that evaluates correctly.

Now its giving me UNDEFINDED VARIABLE errors for every variable in the code.

WHY?!! This code works on my other server, why isn't it working here!?
Reply With Quote
  #17 (permalink)  
Old Sep 23rd, 2005, 13:04
Tim356's Avatar
Reputable Member
Join Date: Nov 2003
Location: Australia
Age: 25
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tim356
What is your register_globals setting set to? Check your phpinfo page for this info. I'm guessing it's off, try turning it on and see what happens (although it's recommended to leave it off, so you may need to build a work around if this is the case).

Although $_Server['php_self'] should work regardless of the register_globals setting...
Reply With Quote
  #18 (permalink)  
Old Sep 23rd, 2005, 16:13
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
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
are you using $_POST['variablename'] for the variables sent by the form? if not, you really ought to be
Reply With Quote
Reply

Tags
php, form, results, php_self, blank

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Publicly viewable form results? wealthy199 Starting Out 5 Sep 27th, 2007 14:59
Getting form results to email as an .html griffster122 Starting Out 1 May 29th, 2007 01:44
Problem with results of form Otter PHP Forum 2 Nov 7th, 2006 13:35
Viewing form results ??????? cat101 PHP Forum 3 Apr 25th, 2006 23:57
Submitting Web form results to a database theproman23 Databases 2 Jun 30th, 2005 13:21


All times are GMT. The time now is 11:43.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43