php problems

Problems with the Windows version of XAMPP, questions, comments, and anything related.

php problems

Postby terry » 14. December 2007 17:16

I have just installed xampp. Apache, php, phpMyAdmin and Mysql all installed okay but am having some problems,when I use a form html page to interact with a php page. The php runs but no php content is revealed, the doc root paths are correct( php.ini & conf), my code is correct and register globals is turned on.
I am using my internal browser. I am a novice user. Not sure where to go
Still Trying !!
terry
 
Posts: 18
Joined: 21. September 2006 11:29
Location: Southampton U.K.

Re: php problems

Postby Izzy » 15. December 2007 02:34

terry wrote:I have just installed xampp. Apache, php, phpMyAdmin and Mysql all installed okay but am having some problems,when I use a form html page to interact with a php page. The php runs but no php content is revealed, the doc root paths are correct( php.ini & conf), my code is correct and register globals is turned on.
I am using my internal browser. I am a novice user. Not sure where to go
...and you are having the server parse your files by calling them in your browser using a URI not by just double clicking on them:
http://localhost/myphpformscript.php
or what ever the URI is for your particular needs.

A good test to see if all your XAMPP components are working is to go to the XAMPP Welcome Page at:
http://localhost
and use the menu items for your testing.
If all are working then there is nothing wrong with the server only the way you are trying to use it.

The files that are accessed from the menu may give you some clues in the code as to how to do things.


===========================================
1. The new DeskTopXampp Launch Control for XAMPP / XAMPPlite
Posted by Ridgewood available from Ridgewood'sDTX web site

2. Build Rich AJAX Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open Source
Fully working with NO donations required to get a user/password
===========================================
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

php problems

Postby terry » 15. December 2007 17:13

I have already checked all the menu files including phpinfo() and they all work okay. When I use my browser, some of the php code actually prints out o the screen. The "<?" tag seems to be ignored. I get the same result when testing my code in my IDE (PHP Coder) I've also tried "<?php"tag but with same result.
Still Trying !!
terry
 
Posts: 18
Joined: 21. September 2006 11:29
Location: Southampton U.K.

Postby KallistaAEnvarou » 15. December 2007 21:21

Could you provide a specific example, with specific results? Are you using <?php php_code;?>HTML, are you including the file...etc? Also, what IDE and browser are you using?
KallistaAEnvarou
 
Posts: 126
Joined: 02. December 2007 17:33
Location: Cold Cold California

php problems

Postby terry » 16. December 2007 13:29

Hi,
Am using Firefox for my internal browser and my IDE is called PHPCoder
A good example of my troubles is:-
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Border Maker</title>

</head>

<body>
<center>
<h1>Border Maker</h1>
<h3>Demonstrates how to read HTML form elements</h3>

<form method = "post"
     action = "borderMaker.php">
   
<h3><i>text box to modify</i></h3>
<textarea name = "basicText"
   rows = "10"
   cols = "45">
Four score and twenty years ago our fathers brought forthon this continent a new nation, conceived in liberty anddedicated to the proposition that all men are created equal. Now we are engaged in agreat cicil war, testing whether that nation or any nation so conceived and so dedicated can long endure.
</textarea>

<table border = 5>
<tr>
   <td><h3>Border Style</h3></td>
   <td colspan = 2><h3>Border Size</h3></td>
   <td colspan = 3><h3>Border Color</h3></td>
</tr>

<tr>
<td>
<select name = borderStyle>
   <option value = "ridge">ridge</option>
   <option value = "groove">groove</option>
   <option value = " double">double</option>
   <option value = " inset">inset</option>
   <option value = "outset">outset</option>
</select></td>
<td>

<select size = 5
name = borderSize>
   <option value = "1">1</option>
   <option value = "2">2</option>
   <option value = "3">3</option>
   <option value = "5">5</option>
   <option value = "10">10</option>
</select></td>

<td>
<input type = "radio"
      name = "sizeType"
     value = "px">pixels<br>
<input type = "radio"
      name = "sizeType"
     value = "pt">points<br>
<input type = "radio"
      name = "sizeType"
     value = "cm">centimeters<br>
<input type = "radio"
      name = "sizeType"
     value = "ins">inches<br></td>

<td class="style2">
<input type = "radio"
      name = "borderColor"
     value = "red">red<br>
<input type = "radio"
      name = "borderColor"
     value = "blue">blue<br>
<input type = "radio"
      name = "borderColor"
     value = "green">green<br>
<input type = "radio"
      name = "borderColor"
     value = "yellow">yellow<br></td>
</tr>
</table>

<input type = "submit"
      value = "show me">
   
</form>
</center>
</body>
</html>

The php page this interact with is:_
Code: Select all
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
       <title>Title here!</title>
</head>
<body>
<center>
<h1>Your Output</h1>
<?php
$theStyle = <<<HERE
 "border-width:$borderSize$sizeType;
  border-style:$borderStyle;
  border-color:$borderColor"
HERE;

print "<div style = $theStyle>";
print $basicText;
print "</span>";
?>
</center>
</body>
</html>

When I run the html page in in my IDE the the only thing that appears from the php page is the title "Your Output". However when I run the same in my browser, in addtion to the title (Your Output) the following also appears:- "; print $basicText; print ""; ?>

The obove code is from a tutorial book I am using to learn PHP.
The sad thing is I've already used this set of code before and it all worked okay. Then had a major crash and lost everything. Am just starting again with a new hard drive

I'm using XP Pro and IIS is currently not installed

Terry
Still Trying !!
terry
 
Posts: 18
Joined: 21. September 2006 11:29
Location: Southampton U.K.

Postby Izzy » 16. December 2007 14:13

First off, the result from http://validator.w3.org/ of file 1 "Border Maker" is
This page is not Valid XHTML 1.0 Transitional!
Result: Failed validation, 65 Errors


File 2 "Title here!"
This page is not Valid -//W3C//DTD HTML 4.0 //EN!
Result: Failed validation, 1 Error


If you are going to declare that your pages conform to certain standards then they have to conform or the server is going to find it hard going.

How are you calling the first file - are you using a URI and is this URI correct?
for example:
http://localhost/bordermaker.html

Not:
http://localhost/htdocs/bordermaker.html
etc.


A php guru will help you with that aspect, as when I tried to replicate your issues all I get is the Your Output title and no border - so there is a php code issue of which I am not familiar.

Maybe this:
print "</span>";
Should be the <div style=$theStyle> closing tag as I don't see an open <span> tag anywhere:
print "</div>";

And I don't see this defined anywhere but as I pointed out I am no php guru.
$basicText

But IMHO there is more php errors perhaps and, as a I suggest, a PHP guru will know straight away what is wrong here.

BTW I did not get any php code being written to the page as if the page was not being parsed by the server as I had both files in the htdocs directory and called the first using:
http://localhost/bordermaker.html


===========================================
1. The new DeskTopXampp Launch Control for XAMPP / XAMPPlite
Posted by Ridgewood available from Ridgewood'sDTX web site

2. Build Rich AJAX Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open Source
Fully working with NO donations required to get a user/password
===========================================
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

php problems

Postby terry » 16. December 2007 16:53

thank you for your prompt reply, file:///C:/Program%20Files/xampp/htdocs/borderMaker.html is the answer to your question.
I am using html 4.0 I mistakenly download the wrong page to you (sorry)
My php code is correct as per the book I use, and the author's web page
http://wally.cs.iupui.edu/n342/
Do you know a php guru who can help? I've tried but know one has ever replied
Terry
Still Trying !!
terry
 
Posts: 18
Joined: 21. September 2006 11:29
Location: Southampton U.K.

Postby Izzy » 16. December 2007 22:23

file:///C:/Program%20Files/xampp/htdocs/borderMaker.html

This will never load the php file through the server, which it must do to parse the php content.

Start your Apache server and load the file in your browser using:
http://localhost/borderMaker.html

This will have the php file parsed through the server and if the php code only produces the heading, Your Output, and nothing else then you will have to look at the reason your php code is not doing what it should.

You will just have to wait until someone who knows php code to spot your post and come up with an answer or contact your book's author or read the php manual.

In the mean time I will take a look at the book you mention and see if I can spot anything that might help.

...And just to prove that php is working as it should be on your XAMPP installation go to the XAMPP Welcome Page at:
http://localhost
Most of the pages are php coded - look at the files in the xampp\htdocs\xampp director, test all the menu items to confirm all is working.



[EDIT]
OK, I have found what is wrong - your code requires register_globals to be on, which is a code security issue that needs to be addressed so register_globals is not required to be on, see the php documentation about how to do this.
http://php.net/manual/en/security.globals.php

php.net wrote:Warning

This feature is DEPRECATED and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.


To turn on register_globals for your test go to:
xampp\apache\bin
and open php.ini in your text editor and find this line and change it to On:
Code: Select all
; You should do your best to write your scripts so that they do not require
; register_globals to be on;  Using form variables as globals can easily lead
; to possible security problems, if the code is not very well thought of.
register_globals = Off

to
register_globals = On

Save the file and restart Apache to have this change recognized.
Now try your http://localhost/borderMaker.html - note the case as Apache is case sensitive.

Make a backup of conf and ini files before editing.
[/EDIT]



===========================================
1. The new DeskTopXampp Launch Control for XAMPP / XAMPPlite
Posted by Ridgewood available from Ridgewood'sDTX web site

2. Build Rich AJAX Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open Source
Fully working with NO donations required to get a user/password
===========================================
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

php probelms

Postby terry » 17. December 2007 12:38

Hi,

Register Globals is "on" and has been throughout. When I use the url "http://localhost/bordermaker.html" I get the same result as before.
The page borderMaker.html fires up but when called, only the title of the PHP page does.
All the files in the menu of PhpMyAdmin work okay, including the "phpinfo()"
My own test version of phpinfo() also opens in the browser.
It all points to errors in my code, but I have built three scripts and non work. One simply calls for a name. to be entered in a box and the name is printed out via the php page. I know that my code is correct. Before my machine crashed they all worked.
Re contacting the author. I have done this in the past and he has been very helpful. But recently I've waited up to three months for a reply. and that is an impossible situation for me. I'm not complaining 'cos I realise how busy he is. He is also a lecturer
Terry
Still Trying !!
terry
 
Posts: 18
Joined: 21. September 2006 11:29
Location: Southampton U.K.

Postby Scory » 17. December 2007 12:59

I still dont believe that register globals is working. Edit borderMaker.php and insert the following code at the top of the file:

Code: Select all
<?php
   foreach ($_POST as $key => $value)
                $GLOBALS[$key] = $value;

?>


Then try again.

Regards
Scory
Scory
 

Postby skuipers » 17. December 2007 15:42

Izzy wrote:OK, I have found what is wrong - your code requires register_globals to be on, which is a code security issue that needs to be addressed so register_globals is not required to be on, see the php documentation about how to do this.
http://php.net/manual/en/security.globals.php

php.net wrote:Warning

This feature is DEPRECATED and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.


Please note that register_globals = On is currently the default setting in XAMPP. Maybe one of the XAMPP designers can explain why this switch is turned on.
skuipers
 
Posts: 99
Joined: 21. January 2005 16:27
Location: The Netherlands

php problems

Postby terry » 17. December 2007 17:59

Yippee !!!
The code supplied by Scory has done the trick. All my code now works when the code
Code: Select all
foreach ($_POST as $key => $value)
                $GLOBALS[$key] = $value;
is added to each php page as the first line after "<?".
Can Scory explain what the code is, and what it does?
Do I have to add it forever to all my php pages?
Why is it that I didn't need to add it to my "test phpinfo()" script?
If ""Register Globals" isn't working, can I download a new php.ini file, and where from?

Terry
Still Trying !!
terry
 
Posts: 18
Joined: 21. September 2006 11:29
Location: Southampton U.K.

Postby Scory » 17. December 2007 23:25

Can Scory explain what the code is, and what it does?


I can. It imports all posted variables into global scope - exactly what "register globals" *would* do, if it *were* activated. And, as i thought, you were wrong, register globals is OFF and not On!

Do I have to add it forever to all my php pages?


You have to add it to all scripts which rely on register globals On. But this is not enough, as my code only imports the "post" variables, not the "get" variables and even not the cookies and even not for sessions, neither for file variables.

You should do the following:

1) Edit the right(!) php.ini (you definately looked into the wrong one!) and set register_globals = On. After then, you may delete the lines i gave to you - it should run without it.

2) At next, get you a PHP documentation, learn a few basics and supply the coding for importing $_GET, $_COOKIE and so on into global scope (similar to my coding). For future reasons because register_globals will be ignored from PHP 6.x

Regards
Scory

P.S.: phpinfo() does not rely on any variables from outside - therefore you dont need to edit that script.
Scory
 

php problems

Postby terry » 18. December 2007 12:01

Hi,
I have three php.ini files called "php.ini", "php.ini-dist" and "php.ini-rec"
Register Globals in php.ini has always been "ON" But the others I've never altered. I was lead to believe that php.ini was the important file. However I've now also altered the remaining two files to Register Globals "ON".
But the problem still persists.
Only when I add the code provided by Scory do the php scripts run
So I guess I have a problem elsewhere ( with the installation of Xampp?)
At least with Scory's code I can continue.
Being a novice I find the php docs difficult but I do understand the only way is to read and read.

Terry
Still Trying !!
terry
 
Posts: 18
Joined: 21. September 2006 11:29
Location: Southampton U.K.

Postby barender » 18. December 2007 13:51

I've had a similar problem and solved it by altering global variables settings to off. i too altered the wrong php.ini file (I think)

The one that did the trick is the one in the apache bin folder. i.e.

c:\xampp\apache\bin\php.ini
barender
 
Posts: 1
Joined: 18. December 2007 13:46

Next

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 55 guests