Panther and PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Mactek
Forum Commoner
Posts: 28
Joined: Tue Oct 28, 2003 1:19 pm
Location: Boston

Panther and PHP

Post by Mactek »

Hi Everyone,

I just upgraded to Panther and i noticed that none of my PHP pages are loading correctly now. Do i have to update/upgrade PHP? Any help would be greatly appreciated, thanks!!
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I'm presuming you're talking about Mac OSX Panther...check the apache config files and check the php config file settings. Make sure they are all set correctly. Also; what type of errors do you get?
Mactek
Forum Commoner
Posts: 28
Joined: Tue Oct 28, 2003 1:19 pm
Location: Boston

Post by Mactek »

Thanks, i reconfigured. PHP seems to be working fine but my SUBMIT for isn't working anymore. It want even go to my post method form. Any ideas?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Please do post some code of the form.
roicinho
Forum Newbie
Posts: 1
Joined: Thu Oct 30, 2003 11:33 am
Location: A Coruña, Galiza. Spain.

forms do not work properly

Post by roicinho »

I have the same problem. Everything but forms seems to work fine

file: index.php
<form action="secondStep.php" method="post">
v1 <input type="text" name="v1">
<input type="submit">
</form>


file: secondStep.php

<?
print("v1:$v1");
?>

and just prints out "v1:"
bobHaddock
Forum Newbie
Posts: 1
Joined: Fri Oct 31, 2003 7:44 am
Location: London

Post by bobHaddock »

I had exactly the same problem. Apps I had written in PHP seemed to query the database ok unless the variables were being passed via the url.

The solution was to edit the php.ini file. By default 'register_globals' is turned off in PHP4.3 whereas earlier versions were turned on by default. Sort out that and everything works a treat.

However, the comments in the php.ini file suggest that register_globals being on is can pose a security issue. Can anyone explain why?

cheers

bob
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

register_globals should be turned off mainly because since it's deprecated you're going to have to get used to life without it. The possible security risks come where you have variables in your script such as $validate, if you aren't careful someone could guess that name and set it to true or yes or 1 or whatever and possibly breach you site's security.

Have a read of Concerning Passing Variables in PHP 4.2+

Examples such as:

Code: Select all

<form action="secondStep.php" method="post">
v1 <input type="text" name="v1">
<input type="submit">
</form>

<?
print("v1:$v1");
?>
need to be amended to something like:

Code: Select all

<form action="secondStep.php" method="post">
v1 <input type="text" name="v1">
<input type="submit">
</form>

<?
print 'v1:'.$_POST['v1'];
?>
Turning register_globals on is only a short term solution whilst you bring your code up to date - it will not exist in all future versions of PHP and you should prepare for that.

Mac
Mactek
Forum Commoner
Posts: 28
Joined: Tue Oct 28, 2003 1:19 pm
Location: Boston

Post by Mactek »

Here is my code. I have register_globals turned ON. My submit form is not working properly. I can get to my form but i cannot get my vars into my insert statement. I think i am using the wrong the wrong syntax around the $_GET. Any ideas? Thanks!!

Code: Select all

<?php 

if (isset($HTTP_GET_VARS['addcomputer'])):

?>
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=GET align="center"> 
<table width="60%" border="10" color="blue" cellpadding="3" cellspacing="5" align="center"> 
<tr> 
<th colspan="2">Enter your data here:</th> 
</tr> 
<tr> 
<td width="50%" align="right">Assest Number:</td> 
<td width="50%"><input type="text" name="assetnum" size="50"></td> 
</tr> 
<tr> 
<td width="30%" align="right">CPU:</td> 
<td width="70%"><input type="text" name="cpu" size="50"></td> 
</tr> 
<tr> 
<td width="30%" align="right">OS:</td> 
<td width="70%"><input type="text" name="os" size="50"></td> 
</tr>
<tr> 
<td width="30%" align="right">Location:</td> 
<td width="70%"><input type="text" name="loc" size="50"></td> 
</tr><tr> 
<td width="30%" align="right">Serial Number:</td> 
<td width="70%"><input type="text" name="sn" size="50"></td> 
</tr><tr> 
<td width="30%" align="right">Mac Address:</td> 
<td width="70%"><input type="text" name="macaddress" size="50"></td> 
</tr><tr> 
<td width="30%" align="right">Warrentee:</td> 
<td width="70%"><input type="text" name="warrentee" size="50"></td> 
</tr> 
</table>
<BR> 
<INPUT TYPE=SUBMIT NAME="submitcomputer" VALUE="SUBMIT"> 
</FORM> 

<?php 
else:

//Connect to the database server
$dbcnx = @mysql_connect(
"localhost", "root", "wheelie"); 
if (!$dbcnx) 
{ 
	echo( "<P>Unable to connect to the " . 
	"database server at this time.</P>" ); 
	exit(); 
}

// Select the mfsmsd database 
if (! @mysql_select_db("mfsmsd") ) 
{ 
	echo( "<P>Unable to locate the mfsmsd " . 
	"database at this time.</P>" ); 
	exit(); 
}

// If a computer has been submitted, 
// add it to the database. 
if ( $submitcomputer  == "SUBMIT" ) 
{ 
	$sql = "INSERT INTO mactrix SET " . 
	"assetnum='".$_GET['assetnum']."'," . 
	"cpu='".$_GET['cpu']."'," . 
	"os='".$_GET['os']."'," . 
	"loc='".$_GET['loc']."'," . 
	"sn='".$_GET['sn']."'," . 
	"macaddress='".$_GET['macaddress']."'," . 
	"warrentee='".$_GET['warrentee']."'" ;
if (mysql_query($sql)) 
{ 
	echo ("<P>Your computer has been added.</P>"); 
} 
else 
{ 
	echo("<P>Error adding submitted computer: " . 
	mysql_error() . "</P>"); 
}
}

//Delete goes here

echo("<P> Here are all the computers " . 
"in our database: </P>"); 

// Request the ID and text of all the computers 
$result = mysql_query( 
"SELECT assetnum, cpu, os, loc, sn, macaddress, warrentee FROM mactrix"); 

if (!$result) 
{ 
	echo("<P>Error performing query: " . 
	mysql_error() . "</P>"); 
	exit(); 
}

// Display the text of each computer in a table
echo "<table border=10\n"; 
echo '<tr><td>Asset Number<td>CPU<td>OS<td>Location<td>Serial Number<td>Mac Address<td>Warrentee</td></tr>';
while ($myrow = mysql_fetch_row($result)) 
{
                printf("<tr><td>%s</td><td>%s<td>%s<td>%s<td>%s<td>%s<td>%s</td></tr>\n",
                $myrow[0], $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5], $myrow[6]);
}
echo "</table>\n";

// When clicked, this link will load this page 
// with the computer submission form displayed. 
echo("<P><A HREF='$PHP_SELF?addcomputer'=1>" . 
"Add a Computer!</A></P>");

endif; 

?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Don't you have a thread on this already?

Mac
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

If I'm not mistaken, you're looking for a variable that doesn't exist.

change addcomputer to submitcomputer, or vice versa.

See if it works now.
hammer32
Forum Newbie
Posts: 3
Joined: Tue Nov 11, 2003 11:32 am

Post by hammer32 »

I'm having what I think is a similar problem. I've got a couple of Audrey touch screens running through a bunch of picture files during the day. After upgrading to OS X 10.3 Panther, the images no longer rotate. I'm pretty much a newbie when it comes to php. I found this code on the web a few years ago and haven't messed with it since.

The problem seems to be with the "$nextURL="http://192.168.1.100$SCRIPT_NAME?index=$nextIndex";" the next picture tries to open at 192.168.1.100?index=1/

Any help would be greatly appreciated!

Thanks!




<?
/****************************************************
Slideshow.php -
Simple script that will generate a slideshow -- a series
of automatically-reloading web pages -- from a directory
of images. To use, simply place this script in the same
directory as your images, and enter the url of the script
in your browser.

For example, if you put your images in ~/public_html/my_images,
and the URL http://www.yourhost.com/my_images would normally then
show the directory of your images, then you can put this
script in that directory, and visit the URL
http://www.yourhost.com/my_images/slideshow.php
and you should get the self-loading slideshow. (If your
web server is set up appropriately, you can also rename the script
to index.php (and probably get rid of any index.html),
and http://www.yourhose.com/my_images should also get you a slide show.
No changes to the script are necessary as the contents of the
directory change - you can add or remove image files at will.

Options:

(If specifying more than one option, separate them with "&")

refresh:
By default, the next image will be loaded every 60 seconds.
To override this, add the "refresh" param, e.g.
http://www.yourhost.com/my_images/slide ... refresh=10
to make it reload every 10 seconds.
The special value of refresh=0 will prevent the pages from
refreshing themselves. In any case, though, you can go to
the next page by clicking on the image.

bgcolor:
You can also override the default background color with the
bgcolor parameter. The following example would give a black
background:
http://www.yourhost.com/my_images/slide ... olor=black

Bug fixes? Comments? mail jamison at graystuff dot com.

****************************************************/

###############
# Constants
###############

# default number of seconds between automatic reload of the page
define("DEFAULT_REFRESH", "60");
define("DEFAULT_BGCOLOR", "black");

# acceptable file extensions for images. The comparison
# will ignore case. The "." should not be included.
# Go ahead and add any that I've missed.
$image_extensions = array('jpg', 'jpeg', 'gif', 'bmp');


#################
# Prepare information for rendering the page
#################

# page refresh: see if there's a defined refresh duration
# (in seconds), defined by the parameter "refresh".
# If so, override the default. The value "0" is a special
# value, indicating that automatic refresh is turned off.


if ($refresh == "") {
$refresh = DEFAULT_REFRESH;
}

# check for background color param
if ($bgcolor == "") {
$bgcolor = DEFAULT_BGCOLOR;
}

# Read in the list of filenames that have any of the
# accepted extensions
$handle=opendir(getcwd());
while (false !== ($file = readdir($handle))) {
# get the file extension
$parts = explode(".", $file);
$extension = end($parts);

# add file to fileArray if it has a matching extension
foreach ($image_extensions as $img_ext) {
if (!strcasecmp($extension, $img_ext)) {
$fileArray[count($fileArray)] = $file;
break;
}
}
}
closedir($handle);
sort($fileArray);

# Which image to display?
# if no index specified, default to first page
if ($index == "") {
$index = 0;
} elseif ($index >= count($fileArray)) {
$index = 0; # loop back to beginning
}

# assemble URL of current image
$imageURL = "./$fileArray[$index]";

#
# assemble URL for next page, to be automatically loaded
#
$nextIndex = ($index+1);
$nextURL="http://192.168.1.100$SCRIPT_NAME?index=$nextIndex";
# append the refresh rate, if not the default
if (strcmp($refresh, DEFAULT_REFRESH)) {
$nextURL = "$nextURL&refresh=$refresh";
}
if (strcmp($bgcolor, DEFAULT_BGCOLOR)) {
$nextURL = "$nextURL&bgcolor=$bgcolor";
}
##########################################################
# Generate the page
##########################################################
?>

<html>
<head>
<script>
function breakout_of_frame()
{
// see http://www.thesitewizard.com/archive/framebreak.shtml
// for an explanation of this script and how to use it on your
// own website
if (top.location != location) {
top.location.href = document.location.href ;
}
}
</script>
<title>Image Slideshow: <? echo $fileArray[$index] ?> </title>

<? # only include the refresh tag if refresh is not 0
if ($refresh != "0") {
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"$refresh;URL=$nextURL\">";
}
?>
</head>
<body onload="breakout_of_frame()" bgcolor="black">
<center>
<a href="http://192.168.1.100/~hammer32/LCARSindex2.html">
<img border=0 hspace=0 vspace=0
src="<? echo $imageURL ?>" alt="<? echo $fileArray[$index] ?>">
</a>
</center>
</body>
Mactek
Forum Commoner
Posts: 28
Joined: Tue Oct 28, 2003 1:19 pm
Location: Boston

Post by Mactek »

Hey Hammer32, have you found a fix for this yet?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

hammer32 wrote:The problem seems to be with the "$nextURL="http://192.168.1.100$SCRIPT_NAME?index=$nextIndex";" the next picture tries to open at 192.168.1.100?index=1/
Exerpt from php manual:
Warning:
In PHP 4.2.0 and later, the default value for the PHP directive register_globals is off. This is a major change in PHP. Having register_globals off affects the set of predefined variables available in the global scope. For example, to get DOCUMENT_ROOT you'll use $_SERVER['DOCUMENT_ROOT'] instead of $DOCUMENT_ROOT, or $_GET['id'] from the URL http://www.example.com/test.php?id=3 instead of $id, or $_ENV['HOME'] instead of $HOME.

For related information on this change, read the configuration entry for register_globals, the security chapter on Using Register Globals , as well as the PHP » 4.1.0 and » 4.2.0 Release Announcements.

Using the available PHP Reserved Predefined Variables, like the superglobal arrays, is preferred.
So try to replace line
$nextURL="http://192.168.1.100$SCRIPT_NAME?index=$nextIndex";
with
$nextURL="http://192.168.1.100{$_SERVER['SCRIPT_NAME']}?index=$nextIndex"
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Reg globs on is a danger if you have undefined vars in your script. Always develop with E_ALL to catch them.
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

Mactek wrote:Here is my code. I have register_globals turned ON. My submit form is not working properly. I can get to my form but i cannot get my vars into my insert statement. I think i am using the wrong the wrong syntax around the $_GET. Any ideas? Thanks!!

Code: Select all

<?php 

if (isset($HTTP_GET_VARS['addcomputer'])):

?>
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=GET align="center"> 
<table width="60%" border="10" color="blue" cellpadding="3" cellspacing="5" align="center"> 
<tr> 
<th colspan="2">Enter your data here:</th> 
</tr> 
<tr> 
<td width="50%" align="right">Assest Number:</td> 
<td width="50%"><input type="text" name="assetnum" size="50"></td> 
</tr> 
<tr> 
<td width="30%" align="right">CPU:</td> 
<td width="70%"><input type="text" name="cpu" size="50"></td> 
</tr> 
<tr> 
<td width="30%" align="right">OS:</td> 
<td width="70%"><input type="text" name="os" size="50"></td> 
</tr>
<tr> 
<td width="30%" align="right">Location:</td> 
<td width="70%"><input type="text" name="loc" size="50"></td> 
</tr><tr> 
<td width="30%" align="right">Serial Number:</td> 
<td width="70%"><input type="text" name="sn" size="50"></td> 
</tr><tr> 
<td width="30%" align="right">Mac Address:</td> 
<td width="70%"><input type="text" name="macaddress" size="50"></td> 
</tr><tr> 
<td width="30%" align="right">Warrentee:</td> 
<td width="70%"><input type="text" name="warrentee" size="50"></td> 
</tr> 
</table>
<BR> 
<INPUT TYPE=SUBMIT NAME="submitcomputer" VALUE="SUBMIT"> 
</FORM> 

<?php 
else:

//Connect to the database server
$dbcnx = @mysql_connect(
"localhost", "root", "wheelie"); 
if (!$dbcnx) 
{ 
	echo( "<P>Unable to connect to the " . 
	"database server at this time.</P>" ); 
	exit(); 
}

// Select the mfsmsd database 
if (! @mysql_select_db("mfsmsd") ) 
{ 
	echo( "<P>Unable to locate the mfsmsd " . 
	"database at this time.</P>" ); 
	exit(); 
}

// If a computer has been submitted, 
// add it to the database. 
if ( $submitcomputer  == "SUBMIT" ) 
{ 
	$sql = "INSERT INTO mactrix SET " . 
	"assetnum='".$_GET['assetnum']."'," . 
	"cpu='".$_GET['cpu']."'," . 
	"os='".$_GET['os']."'," . 
	"loc='".$_GET['loc']."'," . 
	"sn='".$_GET['sn']."'," . 
	"macaddress='".$_GET['macaddress']."'," . 
	"warrentee='".$_GET['warrentee']."'" ;
if (mysql_query($sql)) 
{ 
	echo ("<P>Your computer has been added.</P>"); 
} 
else 
{ 
	echo("<P>Error adding submitted computer: " . 
	mysql_error() . "</P>"); 
}
}

//Delete goes here

echo("<P> Here are all the computers " . 
"in our database: </P>"); 

// Request the ID and text of all the computers 
$result = mysql_query( 
"SELECT assetnum, cpu, os, loc, sn, macaddress, warrentee FROM mactrix"); 

if (!$result) 
{ 
	echo("<P>Error performing query: " . 
	mysql_error() . "</P>"); 
	exit(); 
}

// Display the text of each computer in a table
echo "<table border=10\n"; 
echo '<tr><td>Asset Number<td>CPU<td>OS<td>Location<td>Serial Number<td>Mac Address<td>Warrentee</td></tr>';
while ($myrow = mysql_fetch_row($result)) 
{
                printf("<tr><td>%s</td><td>%s<td>%s<td>%s<td>%s<td>%s<td>%s</td></tr>\n",
                $myrow[0], $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5], $myrow[6]);
}
echo "</table>\n";

// When clicked, this link will load this page 
// with the computer submission form displayed. 
echo("<P><A HREF='$PHP_SELF?addcomputer'=1>" . 
"Add a Computer!</A></P>");

endif; 

?>
Haven't had a good look at your code but your first problem is that you are using the method get and you aren't putting anything in the query string. You should be using the method post. Then you can get the vars.
Post Reply