Re: [PHP] Upload wont work, OS X

2002-11-29 Thread Beth Gore
Hi Magnus,

Your problem was you weren't using the correct part of the $_FILES array 
when using copy();


Cut and Past This:


if ($ok){
  $res = copy($bilde_fil[tmp_name], $path."/".$nyttnavn.$ending);
  print ($res)?"Ferdig, uploadet 
".$nyttnavn.$ending."!":"Sorry, Kunne ikke uploade.";
  print "";
}
?>


The Important bit is the "$bilde_fil[tmp_name]" bit. This means it's 
copying the file from the temporary location on the server to your 
chosen location.

Also, as a side note, replace this too:


$MAX_FILE_SIZE = 100;
$bilde_fil = $_FILES['bilde_fil']; // HTTP_POST_FILES
$nyttnavn = $_POST['nyttnavn'];
$ending = $_POST['ending'];

if($bilde_fil[size] > $MAX_FILE_SIZE)
{
   die("Sorry, Kunne ikke uploade.");
}

$path="upload"; //Mappa som bildene skal havne i (husk den siste '/')


Don't set $MAX_FILE_SIZE using $_POST variables for security reasons - 
someone could very easily alter it in the HTML file!!!

Beth Gore


magnus nilsson wrote:



I have trouble using upload scripts - none of them work on my current 
config. I'vq got php 4.2.3 and global registerd = off. The problem is 
that the script doesnt send the variable $_FILES['my_file'] as it 
should. I can only upload if i hard code the filename into the script.




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] test for ascii or binary string

2002-11-30 Thread Beth Gore
Morgan Hughes wrote:


On Fri, 29 Nov 2002, Jonathan Sharp wrote:

 

Is there a way to determine if a string has ascii or binary data in it?
   

I just wrote this, it seems to work. I've used mhash to generate a 
binary string. It will fail if:

a) The strings use obscure ASCII control characters other than LF, CR 
and Horizontal Tab.
b) You're expecting strings with european charater's with umlouts and 
stuff like that.

You can add these characters to the list of exclusions on line 16 of 
this code.

Hope this helps!!!

Beth Gore




function isbinary($input)
{
/* This simple function returns true if there's any non-standard Ascii 
characters */

$isbinary = 0;

for($x=0;$x < strlen($input); $x++)
{

$c = substr($input,$x,1);

if($c < chr(32) or $c > chr(127))
{
if($c != chr(10) or $c != chr(13) or $c != chr(9)) /* add expected 
european extended characters */
{
$isbinary = 1;
}
}
}

return $isbinary;

}

$binary = mhash(MHASH_MD5,"test");

$ascii = "Hello, this is a normal string;";

$strings = array(1 => $binary, 2=> $ascii);

while(list($id, $string) = each($strings)){

if(isbinary($string)){
echo "string ".$id." verified as binary";
}else{
echo "string ".$id." verified as ascii";
}

}

?>

--



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] last updated ?

2002-11-30 Thread Beth Gore
Paul O'Neil wrote:


Dumb question here but whats the general practice regarding putting a
"website last updated:" entry on a web page? Does the web master manually
enter in today's date in a database table entry and let PHP display. Is it
statically added to the HTML page? Etc...


 

I've just implimented that very thing in my site! Very simple. I have a 
MySQL table that features master site details, including the stylesheet, 
site title, that sort of thing. One column is a Datetime type.

In all the admin pages that add anything new to the site, the last 
update time is updated using:


  $SQL = "UPDATE site SET LastUpdate='".date("Y-m-d G:i:s")."' WHERE 
SiteID=1";
$result = mysql_query($SQL);
?>


Then, in the site's standard footer I have the following:


Last Updated:
  
  $timestamp = strtotime($sitedata["LastUpdate"]);
  echo date("G:i, D \T\h\e jS of M, Y ",$timestamp);

  ?>


This then shows the last update time on the browser, and I also set the 
page to expire at that time, so in that way (I understand) browsers know 
if the page has been updated since you last looked.

--
Beth Gore
http://bethanoia.dyndns.org


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Test links?

2002-11-30 Thread Beth Gore
Rob Packer wrote:


Okay, I'm confused... file, fopen, and fsockopen seem to say not found on
alot valid URLs...  does this look to be correct usage?
$url = $row[0]; // just get the url from the db
$fp = implode ('', file ($url));
if (!$fp) {echo "Unable to access file"; }
else { fclose($fp); echo "The link is working!"; }

It seems I always get this warning...

Warning: Supplied argument is not a valid File-Handle resource in
/web/home/nrc.net/www/robert/links4.php on line 11

If someone can tell me what I'm doing wrong, I'd appreciate it.

Thanks,
   Robert



 

When fopen successfully opens a file it populates an array 
$http_response_header, which you can examine to see if the link works or 
not - I don't believe you can actually get the file itself, but since 
that's not what we're after that's not a problem!

Having said that, fopen produces a very annoying error if it doesn't 
find the page, but I found the following works:



   $SQL = "SELECT linkurl, linkID FROM links";
   $result = mysql_query($SQL);

   while($linkdata = mysql_fetch_array($result)){
  
   $fp = fopen($linkdata['linkurl'],"r");
   if($fp)   
   {
   echo "".$linkdata['linkurl']." is still valid.";
  
   }else{

   echo "".$linkdata['linkurl']." is invalid. Updating 
database... ";
  
   $SQL = "UPDATE links SET status = 0 WHERE linkID = 
'".$linkdata['linkID']."'";
   $result2 = mysql_query($SQL);
   if($result2)
   {
   echo "Database updated";
   }
   }

   }
?>

Rather than deleting the link, it's probably better to set a flag to 
show it was invalid last time you checked, but check it again next time. 
Or you could keep a count of the  number of failed attempts, and delete 
if it goes beyond 3 or so.

Not sure how to supress the warning message that PHP automatically does 
when you haven't got a valid URL though.

Hope this works for you!

Beth Gore
--
http://bethanoia.dyndns.org


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Test links?

2002-12-02 Thread Beth Gore
DL Neil wrote:


Beth,

I noticed this reference to "$http_response_header" and straightaway 
quizzed
the manual, only to find that the only references to it (eg file open) 
lead
nowhere. Have gone through a few other pages, looking to see if I might
happen upon some detail, but failed. Sadly you don't refer to it in 
the code
snippet provided (below). Any code I've attempted blindly has
failed/reported errors.

Please point me in the right direction (otherwise I guess it'll be 
time to
download the new v4.3.0-RC and risk the bleeding edge - which 
according to
the manual does something different anyway...)

Yeah, it's not mentioned anywhere else, I just completely guessed at 
what to do with this and got lucky on the first attempt, but if you do a 
...



print_r($http_response_header);

?>

... you get tons of junk like:

Array (
[0] => HTTP/1.1 200 OK
[1] => Date: Mon, 02 Dec 2002 17:54:47 GMT
[2] => Server: Apache/1.3.27 (Unix) PHP/4.2.3 mod_perl/1.27 
mod_gzip/1.3.19.1a
[3] => Cache-Control: max-age=900, public, must-revalidate, max-age=900
[4] => Expires: Mon, 02 Dec 2002 18:09:47 GMT
[5] => Last-Modified: Mon, 02 Dec 2002 17:51:56 GMT
[6] => ETag: "28de7-cfa4-3deb9dbc"
[7] => Accept-Ranges: bytes
[8] => Content-Length: 53156
[9] => Connection: close
[10] => Content-Type: text/html; charset=iso-8859-1
)

When I first programmed the little function for Rob, I used it to check 
for a 200 status, but it turns out that fopen completely fails UNLESS it 
gets that 200, so it wasn't necessary.


Beth Gore
--
http://bethanoia.dyndns.org


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Validating get and post data

2002-12-02 Thread Beth Gore
Okay, I've just solved my own problem by simply doing:

settype($input,"integer");

but.. I'm puzzled about why the following more complicated solution 
didn't work. The ASCII value for 0 is 48, and for 9 is 57.

The idea was to read a character at a time from the $rawinput string, 
check if it's within the correct range, and if so concantenate it to the 
end of the output string.

However bizarrely this seems to behave incorrectly, as it cuts out "0" 
as well. Can anyone explain why it does this?

function stripnum($rawinput)
	{

	for($x=0;$x < strlen($rawinput);$x++)
	{
		$c = substr($rawinput,$x,1);

		switch($c){

			case ($c > chr(47) and $c < chr(58)):
$output .=$c;
break;

			default:
echo "escaped character at ".$x;
break;
		}

	}

	return $output;
}


I just can't find the bug in my code at all, and even though I found a 
better way to do it, it's annoying me that this didn't work!!!

Beth Gore
--
http://bethanoia.dyndns.org/
rss feed: http://bethanoia.dyndns.org/bethanoia.rss


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Comment Threading

2002-12-02 Thread Beth Gore
Hello,

I'm trying to work out how to do some simple comment threading using 
PHP. I've overridden the blockquote tag in CSS so that it only indents 
from the left.

At the moment comments are simply displayed in reverse chronological 
order as all the replies to a particular post.

I just can't get my head around how to do the threading.

I could add an extra column in the comments table, i.e, "repliedto" 
which would contain the comment ID of the comment the user replied to, 
but that would seem to require some sort of recursion to check whether 
or not a comment has a reply, which I'd rather avoid if I can (mainly 
because I don't think I'm good enough to pull it off)

The other idea would be to have a threadID.. hmm...

table thread: threadID, rootCommmentID, replyCommentID

Then perhaps every time a user replies to a comment, it adds a row to 
the database?

How can I somehow take the data in the comments and/or thread table and 
sort an array of comment data which I can then use to layout the page, 
i.e, adding a different level of indent for each "thread"?

ie:

originalpost
-comment1/thread1(reply to post)

--comment2/thread2(reply to comment1)

---comment3/thread3(reply to comment 2)

comment3/thread4(reply to comment 3)

--comment5/thread1(reply to comment1)

---comment3/thread5(reply to comment 2)

--comment6/thread2(reply to comment1)

-coment7/thread1(reply to post)

Thanks for any help/examples. I really just can't get my head around it.

Beth Gore
--
http://bethanoia.dyndns.org


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Sessions on a shared server

2002-12-21 Thread Beth Gore
Hi,

I've finally got a host and I want to transfer my existing website - I 
have managed to copy and upload my database (wow that was easy.. had 
been dreading it) but now I'm worried that my sessions aren't going 
to work correctly, as I'm sure there are probably other users with 
"userID" variables being set and things like that - with it being a 
shared server, it's obviously a little different to a dedicated one.

Would it be enough to simply set a variable like "mysiteidentifier" and 
only bother checking for other session variables if that's set? Or, do I 
need to override the server's session variables each time I start 
sessions in every page that uses them? I imagine the former would mean 
that other sites would be able to potentially get my session variables, 
which isn't great.

Probably very simple, so sorry if it's incredibly dull!

Thanks,

--
Beth Gore
http://bethanoia.dyndns.org




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] objects within arrays

2002-12-24 Thread Beth Gore
Hi,

I'm really struggling with this - I'm writing a simple webmail client 
for myself (because they've blocked the common ones at work hehe)

Anyway, as soon as I tried to access..

$header = imap_header($inbox,$msgID);

$header->from['mailbox'];

... I get nothing.

I did a print_r on that, and I got..

Array ([0] = StdClass Object([personal] = "blah" ); etc...

so how do I access the data within the Object bit? a simple 
$header->from['personal'] refuses to output anything.

Sorry to be a pain again, I know this is simple language stuff but I 
can't find it in the manual. :)

Beth Gore
--
http://www.habitformer.co.uk



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] objects within arrays

2002-12-24 Thread Beth Gore
This didn't work. Apparently from[] returns an array of objects, however 
I have no idea how to access the object within the array.

print_r gives this:

Array ( [0] => stdClass Object ( [personal] => Beth Gore [mailbox] => 
bethanoia [host] => habitformer.co.uk ) )

I've tried this:

echo $header->from->mailbox."@".$header->from->host;

which doesn't report an error at all, even with full error reporting..

... breaking news.. just cracked it.

echo $header->from[0]->mailbox."@".$header->from[0]->host;

Bascially the array of objects is the whole [0] => stdClass thing.. AGGH!!

Always doing this.

Thanks anyway :)

Beth Gore
--
http://www.habitformer.co.uk


Andrew Brampton wrote:

Big guess but I think maybe:

$header[0]->from['mailbox'];

Also I suggest you turn your PHP Error Level up to E_ALL in your php.ini
file (or temporarly at the top of your scripts with error_reporting
(E_ALL);, this will help debug programs like this :))

Andrew
- Original Message -
From: "Beth Gore" <[EMAIL PROTECTED]>
To: "PHP General List" <[EMAIL PROTECTED]>
Sent: Tuesday, December 24, 2002 6:42 PM
Subject: [PHP] objects within arrays


 

Hi,

I'm really struggling with this - I'm writing a simple webmail client
for myself (because they've blocked the common ones at work hehe)

Anyway, as soon as I tried to access..

$header = imap_header($inbox,$msgID);

$header->from['mailbox'];

... I get nothing.

I did a print_r on that, and I got..

Array ([0] = StdClass Object([personal] = "blah" ); etc...

so how do I access the data within the Object bit? a simple
$header->from['personal'] refuses to output anything.

Sorry to be a pain again, I know this is simple language stuff but I
can't find it in the manual. :)

Beth Gore
--
http://www.habitformer.co.uk



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


   



 




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Sendmail Security

2002-12-28 Thread Beth Gore
Hi,

If I'm taking an URL as user input from in a form, and then emailing 
that URL back to them as part of a larger message, how do I ensure that 
no-one sends anything strange to run shell commands through sendmail?

Could anyone confirm that mail() or even sendmail does take precautions 
against shell commands being executed in the message body of the email?

If not, is there an easy way to remove everything except 
":","/",".","a-Z","0-9"? I've written very complicated things in the 
past and I'm sure there must be an easier way!!!

I've already made sure it's not possible to abuse sendmail with the 
user's email address, but I'm still nervous.

Thanks!

--
Beth Gore
http://www.habitformer.co.uk


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php