PHP Problem

Message Bookmarked
Bookmark Removed
I couldn't find anything in search and trawling the web is taking forever. I'm hoping one of you will have a quick answer for me.

I'm making an LDAP call with PHP - pretty straightforward. I'm putting the results into an indexed array. I want to strip some numbers off one of the fields but can't figure out how to make substr() work in my array. Do I need to make an associative array instead? Is there a very simple solution and I'm just a moran?

Miss Misery xox (MissMiseryTX), Tuesday, 23 May 2006 12:13 (nineteen years ago)

copy array element into local variable, substr that and copy it back?

use print_r() on the array to see what it looks like. should then just be a matter of accessing via a[b][c][d]... to get at array element.

koogs (koogs), Tuesday, 23 May 2006 12:30 (nineteen years ago)

I tried the first bit but not print_r(). Also this is a multidimensional array in a loop. I hate working with arrays, I really do.

Miss Misery xox (MissMiseryTX), Tuesday, 23 May 2006 12:34 (nineteen years ago)

http://www.laist.com/images/lapd.gif

ZOT! (davidcorp), Tuesday, 23 May 2006 12:53 (nineteen years ago)

Thank you Jon. I forgot to mention that I've been working with php for about 3 weeks. But it is very similar to other scripting languages I've worked with so, until now, I've been able to do everything I needed.

and that is a good site.

Miss Misery xox (MissMiseryTX), Tuesday, 23 May 2006 12:55 (nineteen years ago)

When I need help with php I just hit

php.net/functionnameorwhatever

and it usually redirects me to what i need

JW (ex machina), Tuesday, 23 May 2006 13:11 (nineteen years ago)

four months pass...
I've got an urgent PHP problem - all help gratefully appreciated in advance.

This website of mine has gone live today. I'm still finishing off bits of info, but I've noticed the Mailing List at the top doesn't work - it goes to a 500 Internal Error page.

I've done one of these several times before, and so naively assumed it would work and didn't test it. Now I'm panicking - the documentary maker himself is in the newspapers today, so I need urgent help on fixing this. The form itself goes like this:

<form action="mlist.php" method="post" name="mailer">

The input like this:

<input name="ADDRESS" type="text" size="25,1" maxlength="80" />

And 'mlist.php' goes like this:

<?php


$ADDRESS = stripslashes($ADDRESS);

$filename = "list.html";

$fp = fopen( $filename,"r");

$OldData = fread($fp, 100000);

fclose( $fp );

$Input = "$ADDRESS<br><br>";


$New = "$OldData$Input";

$fp = fopen( $filename,"w");

if(!$fp) die("&Cannot write $filename ......&");

fwrite($fp, $New, 1000000);

fclose( $fp );

include("index.html");


?>


Can anyone please spot the obvious mistake? Again, thanks in advance.

Huey in Melbourne (Huey in Melbourne), Saturday, 30 September 2006 03:29 (nineteen years ago)

Does your server have register_globals turned on? If not, replace $ADDRESS with $_REQUEST['ADDRESS']

Forest Pines (ForestPines), Saturday, 30 September 2006 05:34 (nineteen years ago)

Do you mean all the throughout (3 instances), like this:

<?php


$_REQUEST['ADDRESS'] = stripslashes($_REQUEST['ADDRESS']);

$filename = "list.html";

$fp = fopen( $filename,"r");

$OldData = fread($fp, 100000);

fclose( $fp );

$Input = "$_REQUEST['ADDRESS']<br><br>";


$New = "$OldData$Input";

$fp = fopen( $filename,"w");

if(!$fp) die("&Cannot write $filename ......&");

fwrite($fp, $New, 1000000);

fclose( $fp );

include("index.html");


?>


Huey in Melbourne (Huey in Melbourne), Saturday, 30 September 2006 06:18 (nineteen years ago)

Yes. Or, to make it easier, you could just put:

$ADDRESS = $_REQUEST['ADDRESS'];

at the top, instead.

Secondly, do you have access to the server's error_log file? That usually records a semi-useful error message for a 500 Internal Error, rather more informative than the one that the browser displays.

Forest Pines (ForestPines), Saturday, 30 September 2006 06:30 (nineteen years ago)

FP, thanks for this I'll give it a go.
And no, sadly I don't have access to a log file - the owner of the space just gave me the FTP details for uploading today, and as far as I can tell there's not one for me to access. He's gone bush, too, so I can't get hold of him.
I'll let you know how I get on. Thanks again.

Huey in Melbourne (Huey in Melbourne), Saturday, 30 September 2006 06:39 (nineteen years ago)

Most webhosting companies give you read access to the logfiles somewhere in the FTP space. Look for a non-public folder that's outside the httpdocs folder (if you have one of those), called 'logs' or 'statistics' or something like that.

Forest Pines (ForestPines), Saturday, 30 September 2006 06:42 (nineteen years ago)

OK, I gave this a go:
$ADDRESS = $_REQUEST['ADDRESS'];
But no difference.

Sadly, I can't find any reference to any log or statistic file.

Nor can I find, in the server's control panel, any feature whereby CGI has to be activated , or not, which is a problem I experience before.

Is there any other quick way of doing this that doesn't involve PHP, do you know?

Huey in Melbourne (Huey in Melbourne), Saturday, 30 September 2006 07:35 (nineteen years ago)

Have you checked that the list.html file is a) readable b) writable by the "nobody" user

In any case, a better way to write it would be

1) Open the file in append mode - fopen($filename, "a");
2) Lock it
3) Move to the end of the file - fseek ($file, 0, SEEK_END);
4) Write to the file
5) Close it

This should remove any concurrency problems - if you don't do this, two people using the site at the same time will wreck your data.

Forest Pines (ForestPines), Saturday, 30 September 2006 07:46 (nineteen years ago)

FP, just to let you know, after quite literally falling asleep on the problem, today it seems to be working.

I guess the stern email I sent to the server folks did something, though they haven't personally replied.

Thanks once again for your help.

Huey in Melbourne (Huey in Melbourne), Sunday, 1 October 2006 07:42 (nineteen years ago)


You must be logged in to post. Please either login here, or if you are not registered, you may register here.