Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #8512 > unrolled thread

randomly sorting files in php

Started byCal Dershowitz <cal@example.invalid>
First post2013-02-28 17:49 -0800
Last post2013-03-14 03:39 -0700
Articles 11 on this page of 51 — 15 participants

Back to article view | Back to comp.lang.php


Contents

  randomly sorting files in php Cal Dershowitz <cal@example.invalid> - 2013-02-28 17:49 -0800
    Re: randomly sorting files in php Jerry Stuckle <jstucklex@attglobal.net> - 2013-02-28 23:45 -0500
      Re: randomly sorting files in php Cal Dershowitz <cal@example.invalid> - 2013-02-28 22:23 -0800
        Re: randomly sorting files in php David Robley <me@home.invalid> - 2013-03-01 17:24 +1030
          Re: randomly sorting files in php Cal Dershowitz <cal@example.invalid> - 2013-03-03 18:59 -0800
            getting perl and php to talk to each other,  was Re: randomly sorting files in php Cal Dershowitz <cal@example.invalid> - 2013-03-05 01:19 -0800
              Re: getting perl and php to talk to each other,  was Re: randomly sorting   files in php "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-03-05 19:43 +0100
                Re: getting perl and php to talk to each other,  was Re: randomly sorting   files in php The Natural Philosopher <tnp@invalid.invalid> - 2013-03-05 19:20 +0000
              Re: getting perl and php to talk to each other Ben Morrow <ben@morrow.me.uk> - 2013-03-05 22:06 +0000
                Re: getting perl and php to talk to each other Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-06 00:20 +0100
                  Re: getting perl and php to talk to each other Ben Morrow <ben@morrow.me.uk> - 2013-03-05 23:59 +0000
                    Re: getting perl and php to talk to each other The Natural Philosopher <tnp@invalid.invalid> - 2013-03-06 01:01 +0000
                    Re: getting perl and php to talk to each other Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-05 20:08 -0500
                      Re: getting perl and php to talk to each other Cal Dershowitz <cal@example.invalid> - 2013-03-06 22:37 -0800
                        Re: getting perl and php to talk to each other Ben Morrow <ben@morrow.me.uk> - 2013-03-07 06:57 +0000
                          Re: getting perl and php to talk to each other Cal Dershowitz <cal@example.invalid> - 2013-03-07 00:52 -0800
                            Re: getting perl and php to talk to each other Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-07 08:17 -0500
                              Re: getting perl and php to talk to each other Cal Dershowitz <cal@example.invalid> - 2013-03-14 03:41 -0700
                                Re: getting perl and php to talk to each other The Natural Philosopher <tnp@invalid.invalid> - 2013-03-14 11:14 +0000
                                  Re: getting perl and php to talk to each other Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-14 08:06 -0400
                                Re: getting perl and php to talk to each other Jürgen Exner <jurgenex@hotmail.com> - 2013-03-14 04:18 -0700
                                  Re: getting perl and php to talk to each other Scott Johnson <noonehome@chalupasworld.com> - 2013-03-14 05:38 -0700
                            Re: getting perl and php to talk to each other Ben Morrow <ben@morrow.me.uk> - 2013-03-07 14:25 +0000
                        Re: getting perl and php to talk to each other Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-07 08:14 -0500
                    Re: getting perl and php to talk to each other Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-06 02:08 +0100
                Re: getting perl and php to talk to each other Cal Dershowitz <cal@example.invalid> - 2013-03-06 22:53 -0800
                  Re: getting perl and php to talk to each other "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-03-07 09:46 +0100
                    Re: getting perl and php to talk to each other David Robley <me@home.invalid> - 2013-03-07 21:43 +1030
                      Re: getting perl and php to talk to each other "Peter H. Coffin" <hellsop@ninehells.com> - 2013-03-07 07:32 -0600
                  Re: getting perl and php to talk to each other SwissCheese <swisscheese@cfl.rr.com> - 2013-03-07 06:28 -0500
                    Re: getting perl and php to talk to each other Ben Morrow <ben@morrow.me.uk> - 2013-03-07 14:33 +0000
                      Re: getting perl and php to talk to each other Cal Dershowitz <cal@example.invalid> - 2013-03-14 02:16 -0700
                    Re: getting perl and php to talk to each other Cal Dershowitz <cal@example.invalid> - 2013-03-14 03:28 -0700
                      Re: getting perl and php to talk to each other SwissCheese <swisscheese@cfl.rr.com> - 2013-03-14 06:51 -0400
                        Re: getting perl and php to talk to each other Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-18 12:54 +0100
                          Re: getting perl and php to talk to each other SwissCheese <swisscheese@cfl.rr.com> - 2013-03-18 20:23 -0400
                  Re: getting perl and php to talk to each other alexd <troffasky@hotmail.com> - 2013-03-07 19:09 +0000
                    Re: getting perl and php to talk to each other Henry Law <news@lawshouse.org> - 2013-03-07 20:09 +0000
                      Re: getting perl and php to talk to each other Cal Dershowitz <cal@example.invalid> - 2013-03-14 02:23 -0700
                    Re: getting perl and php to talk to each other The Natural Philosopher <tnp@invalid.invalid> - 2013-03-07 20:43 +0000
                      Re: getting perl and php to talk to each other Alastair Black <abqab.nemo@example.net> - 2013-03-07 14:47 -0700
                        Re: getting perl and php to talk to each other "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-03-07 23:11 +0100
                          Re: getting perl and php to talk to each other Alastair Black <abqab.nemo@example.net> - 2013-03-07 15:50 -0700
                      Re: getting perl and php to talk to each other Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-07 19:45 -0500
                        Re: getting perl and php to talk to each other Cal Dershowitz <cal@example.invalid> - 2013-03-14 02:19 -0700
                          Re: getting perl and php to talk to each other Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-14 07:55 -0400
                      where to put the binaries was Re: getting perl and php to talk to each other Cal Dershowitz <cal@example.invalid> - 2013-03-14 03:11 -0700
                        Re: where to put the binaries was Re: getting perl and php to talk to each other The Natural Philosopher <tnp@invalid.invalid> - 2013-03-14 11:12 +0000
                        Re: where to put the binaries was Re: getting perl and php to talk to each other Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-14 08:04 -0400
    Re: randomly sorting files in php Captain Paralytic <paul_lautman@yahoo.com> - 2013-03-04 02:45 -0800
      Re: randomly sorting files in php Cal Dershowitz <cal@example.invalid> - 2013-03-14 03:39 -0700

Page 3 of 3 — ← Prev page 1 2 [3]


#8580 — Re: getting perl and php to talk to each other

FromAlastair Black <abqab.nemo@example.net>
Date2013-03-07 14:47 -0700
SubjectRe: getting perl and php to talk to each other
Message-ID<khb25o$dij$1@n102.xanadu-bbs.net>
In reply to#8579
On 03/07/2013 01:43 PM, The Natural Philosopher wrote:
> On 07/03/13 19:09, alexd wrote:
>> Cal Dershowitz (for it is he) wrote:
>>
>>> Struggling.
>>>
>>> $ php-config --libs
>>> No command 'php-config' found, did you mean:
>>> Command 'pdp-config' from package 'pd-pdp' (universe)
>>> Command 'php-config5' from package 'php5-dev' (main)
>>> php-config: command not found
>>
>> I should think that anybody with a passing familiarity with package
>> management would be able to work out what this output is telling them.
>>
> a passing familiarity with package management is not a requirement for
> running PHP or posting in this NG.
>
> NOr is installation of php development files and utilities a requirement
> fora basic LAMP setup.
>
>

If you say to the car dealer "I would like to buy
a cerise van" and the car dealer says "We don't
have cerise, how about red?" it makes no sense to
go to the coffee shop down the street and ask the
folks there "Why doesn't that car dealer have
cerise cars?"

Alastair

[toc] | [prev] | [next] | [standalone]


#8582 — Re: getting perl and php to talk to each other

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2013-03-07 23:11 +0100
SubjectRe: getting perl and php to talk to each other
Message-ID<apshlbF5qmkU1@mid.uni-berlin.de>
In reply to#8580
Am 07.03.2013 22:47, schrieb Alastair Black:
> On 03/07/2013 01:43 PM, The Natural Philosopher wrote:
>> On 07/03/13 19:09, alexd wrote:
>>> Cal Dershowitz (for it is he) wrote:
>>>
>>>> Struggling.
>>>>
>>>> $ php-config --libs
>>>> No command 'php-config' found, did you mean:
>>>> Command 'pdp-config' from package 'pd-pdp' (universe)
>>>> Command 'php-config5' from package 'php5-dev' (main)
>>>> php-config: command not found
>>>
>>> I should think that anybody with a passing familiarity with package
>>> management would be able to work out what this output is telling them.
>>>
>> a passing familiarity with package management is not a requirement for
>> running PHP or posting in this NG.
>>
>> NOr is installation of php development files and utilities a requirement
>> fora basic LAMP setup.
>>
>>
> 
> If you say to the car dealer "I would like to buy
> a cerise van" and the car dealer says "We don't
> have cerise, how about red?" it makes no sense to
> go to the coffee shop down the street and ask the
> folks there "Why doesn't that car dealer have
> cerise cars?"

Your are trying to explain with an analogy, requiring abstraction, a problem you
could understand with simple logic.

/Str.

[toc] | [prev] | [next] | [standalone]


#8583 — Re: getting perl and php to talk to each other

FromAlastair Black <abqab.nemo@example.net>
Date2013-03-07 15:50 -0700
SubjectRe: getting perl and php to talk to each other
Message-ID<khb5sp$efv$1@n102.xanadu-bbs.net>
In reply to#8582
On 03/07/2013 03:11 PM, M. Strobel wrote:
> Am 07.03.2013 22:47, schrieb Alastair Black:
>> On 03/07/2013 01:43 PM, The Natural Philosopher wrote:
>>> On 07/03/13 19:09, alexd wrote:
>>>> Cal Dershowitz (for it is he) wrote:
>>>>
>>>>> Struggling.
>>>>>
>>>>> $ php-config --libs
>>>>> No command 'php-config' found, did you mean:
>>>>> Command 'pdp-config' from package 'pd-pdp' (universe)
>>>>> Command 'php-config5' from package 'php5-dev' (main)
>>>>> php-config: command not found
>>>>
>>>> I should think that anybody with a passing familiarity with package
>>>> management would be able to work out what this output is telling them.
>>>>
>>> a passing familiarity with package management is not a requirement for
>>> running PHP or posting in this NG.
>>>
>>> NOr is installation of php development files and utilities a requirement
>>> fora basic LAMP setup.
>>>
>>>
>>
>> If you say to the car dealer "I would like to buy
>> a cerise van" and the car dealer says "We don't
>> have cerise, how about red?" it makes no sense to
>> go to the coffee shop down the street and ask the
>> folks there "Why doesn't that car dealer have
>> cerise cars?"
>
> Your are trying to explain with an analogy, requiring abstraction, a problem you
> could understand with simple logic.

Why, yeees. Or even reading the actual words of
the actual original question, actually. Actually *read*,
I mean.

 >>>>> No command 'php-config' found, did you mean:
 >>>>> Command 'php-config5' from package 'php5-dev' (main)

Alastair    <-- never owned a red van

[toc] | [prev] | [next] | [standalone]


#8584 — Re: getting perl and php to talk to each other

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-03-07 19:45 -0500
SubjectRe: getting perl and php to talk to each other
Message-ID<khbc96$n53$1@dont-email.me>
In reply to#8579
On 3/7/2013 3:43 PM, The Natural Philosopher wrote:
> On 07/03/13 19:09, alexd wrote:
>> Cal Dershowitz (for it is he) wrote:
>>
>>> Struggling.
>>>
>>> $ php-config --libs
>>> No command 'php-config' found, did you mean:
>>> Command 'pdp-config' from package 'pd-pdp' (universe)
>>> Command 'php-config5' from package 'php5-dev' (main)
>>> php-config: command not found
>>
>> I should think that anybody with a passing familiarity with package
>> management would be able to work out what this output is telling them.
>>
> a passing familiarity with package management is not a requirement for
> running PHP or posting in this NG.
>
> NOr is installation of php development files and utilities a requirement
> fora basic LAMP setup.
>
>

No, but trying to get two different languages working together takes 
more expertise than just installing LAMP.  Of course, it's nothing a 
troll like you would understand.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#8650 — Re: getting perl and php to talk to each other

FromCal Dershowitz <cal@example.invalid>
Date2013-03-14 02:19 -0700
SubjectRe: getting perl and php to talk to each other
Message-ID<beudnRA9qJmFC9zMnZ2dnUVZ_tQAAAAA@supernews.com>
In reply to#8584
On 03/07/2013 04:45 PM, Jerry Stuckle wrote:
> On 3/7/2013 3:43 PM, The Natural Philosopher wrote:
>> On 07/03/13 19:09, alexd wrote:
>>> Cal Dershowitz (for it is he) wrote:
>>>
>>>> Struggling.
>>>>
>>>> $ php-config --libs
>>>> No command 'php-config' found, did you mean:
>>>> Command 'pdp-config' from package 'pd-pdp' (universe)
>>>> Command 'php-config5' from package 'php5-dev' (main)
>>>> php-config: command not found
>>>
>>> I should think that anybody with a passing familiarity with package
>>> management would be able to work out what this output is telling them.
>>>
>> a passing familiarity with package management is not a requirement for
>> running PHP or posting in this NG.
>>
>> NOr is installation of php development files and utilities a requirement
>> fora basic LAMP setup.
>>
>>
>
> No, but trying to get two different languages working together takes
> more expertise than just installing LAMP.  Of course, it's nothing a
> troll like you would understand.
>

Get the motherfuck off my thread.

-- 
Cal

[toc] | [prev] | [next] | [standalone]


#8660 — Re: getting perl and php to talk to each other

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-03-14 07:55 -0400
SubjectRe: getting perl and php to talk to each other
Message-ID<khsdnq$l2m$1@dont-email.me>
In reply to#8650
On 3/14/2013 5:19 AM, Cal Dershowitz wrote:
> On 03/07/2013 04:45 PM, Jerry Stuckle wrote:
>> On 3/7/2013 3:43 PM, The Natural Philosopher wrote:
>>> On 07/03/13 19:09, alexd wrote:
>>>> Cal Dershowitz (for it is he) wrote:
>>>>
>>>>> Struggling.
>>>>>
>>>>> $ php-config --libs
>>>>> No command 'php-config' found, did you mean:
>>>>> Command 'pdp-config' from package 'pd-pdp' (universe)
>>>>> Command 'php-config5' from package 'php5-dev' (main)
>>>>> php-config: command not found
>>>>
>>>> I should think that anybody with a passing familiarity with package
>>>> management would be able to work out what this output is telling them.
>>>>
>>> a passing familiarity with package management is not a requirement for
>>> running PHP or posting in this NG.
>>>
>>> NOr is installation of php development files and utilities a requirement
>>> fora basic LAMP setup.
>>>
>>>
>>
>> No, but trying to get two different languages working together takes
>> more expertise than just installing LAMP.  Of course, it's nothing a
>> troll like you would understand.
>>
>
> Get the motherfuck off my thread.
>

You really do know how to win friends and influence people, don't you? 
Well, you're not going to get much help here with that attitude.

But then idiots never are very smart.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#8652 — where to put the binaries was Re: getting perl and php to talk to each other

FromCal Dershowitz <cal@example.invalid>
Date2013-03-14 03:11 -0700
Subjectwhere to put the binaries was Re: getting perl and php to talk to each other
Message-ID<JZGdnTN-1snZP9zMnZ2dnUVZ_gidnZ2d@supernews.com>
In reply to#8579
On 03/07/2013 12:43 PM, The Natural Philosopher wrote:

> a passing familiarity with package management is not a requirement for
> running PHP or posting in this NG.
>
> NOr is installation of php development files and utilities a requirement
> fora basic LAMP setup.
>
>

NP, I've been reading you for a while now.  Did you give me the name of 
a newsgroup where they consider webstuff ontopic?

I'm rather convinced that scripting languages are my meal ticket this 
month, so much so that I'm making it happen with my rudimentary 
webtools.  This is what I call output:

http://merrillpjensen.com/food_4.html

This is a powerful medium, where one can intermix binaries and text.  My 
problem now is that it's not a discrete medium without me attending 
endlessly to obfuscations with files that I would much just rather have 
as themselves, and the only way you can see them is if php lets you with 
an authentication level equal to my level of give a crap.

It's been a while since I did a source listing, so I would like to do 
so, now that I can ask better questions.

In my line of work, I find myself taking a lot of pictures, because it 
shows what I do for my clients.  My clients are honest to God Amis whose 
privacy is a matter for me to stake my integrity on, and I have enough 
of them that I know that their preferences to privacy vary, depending 
mostly on age, btw.  Little bit on class.  whatevs.

The rub is that I need to be able to show what I do to market the things 
that I do.  These are the scripts I'm using to pull it off now:

I run a bash script to handle the images that get chosen from my camera:

$ cat nikon_bash3.sh
#!/bin/bash

set -e
PARENTDIR='cleaning'
DIR='images1'
cd ${PARENTDIR}
mkdir -p $DIR
cp *.JPG $DIR
cd $DIR
ls -l
mogrify -resize 800x600! *
rename 'y/A-Z/a-z/' *.JPG
ls -l
cd ..
cd ..
pwd
sudo fredify2.sh
$

I have several versions of this.  Very vanilla.

$ cd cleaning
$ cat food_ftp1.pl
#!/usr/bin/perl -w
use strict;
use 5.010;
use Net::FTP;
use HTML::Entities;
use File::Basename;
use Cwd;

# diamond bracket in paragraph mode declared at top scope
$/ = "";

## usage needs 1 arg from argv my_ftp

#identity and config
my $ident = 'my_ftp.txt';
my ( $config, $domain );
$config = do($ident);
unless ($config) {
     die("read error: $!")  if $!;
     die("parse error: $@") if $@;
}
$domain = $config->{ $ARGV[0] };
die("unknown domain: $ARGV[0]") unless $domain;

# get name of directory
my $dir = cwd;
print "dir is $dir \n";
my $word = basename($dir);
print "word is $word \n";

# get files
my $path  = "images1/";
my @files = <$path*>;
print " files are @files\n";

#dial up the server
my $ftp = Net::FTP->new( $domain->{domain}, Debug => 1, Passive => 1 )
   or die "Can't connect: $@\n";
$ftp->login( $domain->{username}, $domain->{password} )
   or die "Couldn't login\n";
$ftp->binary();

# get files from remote root that end in html:
my @remote_files = $ftp->ls();

# make unique .html choice
my @matching = map /${word}_(\d+)\.html/, @remote_files;
print "matching is @matching\n";
push( @matching, 0 );
@matching = sort { $a <=> $b } @matching;
my $winner  = pop @matching;
my $newnum1 = $winner + 1;
my $word2   = "${word}_$newnum1";
print " new word is  $word2\n";
my $html_file = "${word2}.html";
print "html file is  $html_file\n";

#make directory in images to correspond

$ftp->cwd("images/")
   or die "Cannot change working directory ", $ftp->message;
$ftp->mkdir("${word2}/")
   or warn "Cannot create directory ", $ftp->message;
$ftp->cdup();

# create file for html stubouts
open( my $fh, '>', $html_file )
   or die("Can't open $html_file for writing: $!");

my $header = "template_stuff/header1.txt";

# write in the header
open( my $gh, '<', $header ) or die("Can't open: $!");

while (<$gh>) {
     print $fh $_;
}

my $h1 = 'Resolving conflicts';
my $h2 = 'and moving forward';
print $fh "<h1>$h1</h1>\n";
print $fh "<h2>$h2</h2>\n";

#create template outside loop

my $template = <<'TEMPLATE';
<img src="/images/%s"/>

<p>%s</p>
TEMPLATE

open my $CAPTIONS, "<", "food1.txt" or die "file not there\n";

$ftp->cwd("/images/${word2}/") or die "cwd failed $@\n";

# main control
for my $name (@files) {
     print "name is $name\n";
     my  $remote_file = basename($name);
     print "remote is $remote_file\n";
     $ftp->put( $name, $remote_file ) or die "put failed $!\n";

     # captions
     my $caption = <$CAPTIONS>;
     $caption = encode_entities($caption);
     printf $fh $template, "${word2}/" . $remote_file, $caption;
}

# write in the footer
my $footer = "template_stuff/footer1.txt";
open( my $hh, '<', $footer )
   or die("Can't open: $!");

while (<$hh>) {
     print $fh $_;
}

close $fh;
$ftp->pwd();
$ftp->ls();
$ftp->cdup()          or die "cdup failed $@\n";
$ftp->cdup()          or die "cdup failed $@\n";
$ftp->put($html_file) or die "put failed $@\n";

$

This has so far been my home-cooked perl version of static web dev, but 
I want to see if php can obviate all the go***a%n filing-about that you 
have to do to maintain the privacies of the the binaries shown.  These 
images are my shack so I don't care so much anymore.  I also use this 
tool chain to lay down the law with people a bit; it's a very direct medium:

http://merrillpjensen.com/cleaning_1.html

Q1)  How do I design a website where the binaries aren't there for the 
taking unless php thinks you have done some act of authentication to see 
them?

Q2)  What's a good first book for php?
-- 
Cal



[toc] | [prev] | [next] | [standalone]


#8657 — Re: where to put the binaries was Re: getting perl and php to talk to each other

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2013-03-14 11:12 +0000
SubjectRe: where to put the binaries was Re: getting perl and php to talk to each other
Message-ID<khsbb3$t4h$1@news.albasani.net>
In reply to#8652
On 14/03/13 10:11, Cal Dershowitz wrote:

> Q1)  How do I design a website where the binaries aren't there for the
> taking unless php thinks you have done some act of authentication to see
> them?
>
Two standard ways.

1/. put them all in different directories and pop a .htaccess and 
password file in each one so that APACHE denies access without a login.

This is pure Apache and nothing to do with PHP at all. If apache is 
coinfigured to respect this method teh general form is

.htaccess
==========

AuthType Basic
AuthName "My Private Picture access"
AuthUserFile /var/www.mysite.com/this_directory/.htpasswd
Require valid-user

That tells apache to deny unauthorised access, and look in
/var/www.mysite.com/this_directory/.htpasswd

for name:password pairs.
.htpasswd
==========
rufus:OMtQ1VFqr!2dY

This contains a user name and a hashed password and is created using teh 
htpasswd utility that comes with apache.

http://httpd.apache.org/docs/2.2/programs/htpasswd.html

If you have access to the total apache installation, this is trivial, 
less so if you are merely uploading files to someone else's


2/. use cookies (sessions) in (php) via a login page: That essentially 
sets a php variable to reflect the users session. So you if the user 
attempts to access the page, and he is not logged in, the php should 
present him with a login page, and name and password (are filled in and 
submitted to the same page, these are then used to set the cookie, and 
all subsequent invocation's of that page with the cookie set will allow 
access to the directory via the PHP script.

You set and read cookies either using sessions, or doirectly

e.g.

  $_COOKIE["K9PA70634H"]=$cookie;
Cookies are an array of name=>value pairs in PHP global space.
"K9PA70634H" is just an arbitrary string.
AS is what's in $cookie...in my application every time a user logs in I 
look in a database to see if he has the right password, and if he has, 
generate a random cookie and store that in the database. If he comes 
back with the cookie still set, then that's a match and access is 
seamless. If the cookie has timed out or its different from that in the 
database, he gets to login again.

i.e. a not especially relevant code snippet..user may have set name and 
password in $_POST['name'] and $_POST['password']: $_POST['persistent'] 
i sset if he wants to stay logged in forever..

	$result=mysql_query(sprintf("select id, password, email from people 
where familiar='%s'",$_POST['name']));
	if( $result && mysql_numrows($result)>0) // user at least exists
		{
		if($_POST['password'] != mysql_result($result,0,'password'))
			{
			$error="Incorrect password";
			$email=mysql_result($result,0,'email');
			display_login($error);
			}
		else  // by golly we have a match!
			{
			 if(!isset($_POST['persistent']))
			 	$_POST['persistent']='no';
			 $id=mysql_result($result,0,'id');
			 // generate a cookie and store it and echo it back to the users browser.
			 $cookie=randomstring(10);
			 mysql_query(sprintf("update people set cookie='%s', timeout='%s' 
where id = '%d'",$cookie, $_POST['persistent'],$id));
			 // pretend we already HAVE a valid cookie from the browser..so that 
when getlogname is called it all 'works' and a new cookie will get issued
			 $_COOKIE["K9PA70634H"]=$cookie;
			 display_success();
			}
		}
	else
		{
		$error="No such name is registered";
		display_login($error,$email);
		}
	}

So that's how the name password gets stuck in the DB and a cookie is 
attached.

This function checks the cookie is valid, and CHANGES IT EVERY TIME THE 
USER READS A PAGE.

Additional security so that even if - say some hacker knows what the 
cookie was last time, it wont work if the user has accessed the page again

function getlogname()
	{
	global $logname; // system wide for the duration
	$id=0; // set default of not found
	if(isset($_COOKIE["K9PA70634H"]))
		{
		$cookie=$_COOKIE["K9PA70634H"];
		if(strlen($cookie)>8)
			{
			$query=sprintf("select id , familiar, timeout from people where 
cookie ='%s'",$cookie);
			$result=mysql_query($query);
			if ($result && mysql_num_rows($result)==1)
				{
				$id=mysql_result($result,0, 'id');
				$logname=mysql_result($result,0, 'familiar');
				$persistent=mysql_result($result,0, 'timeout');
				$cookie=randomstring(10); // generate new cookie so stolen cookies 
wont work..this also means using a new machine will wipe out stored cookies
				if($persistent=='yes')
					setcookie("K9PA70634H",$cookie,time() + (86400 * 365)); // give em 
a year before it expires.
				else
					setcookie("K9PA70634H",$cookie); // issue session only cookie
				// now update access time and ip address
				$query=sprintf("update people set last_ip='%s',cookie='%s', 
last_accessed='%s' where id='%d'",$ipaddr=$_SERVER['REMOTE_ADDR'] 
,$cookie, date("Y-m-d H:i:s"), $id);
				mysql_query($query);
				}
			}
		}
	return $id;
	}



Getlogname in my case is called every page that has access to 'sensitive 
data' and checks that either the cookie is set, or invites the user to 
log in before proceeding.


If you went that sort of route you would probably hold a set of 
directories or pictures that user was allowed to access in the database.

Going the PHP route and using cookies and or databases is probably the 
slicker neater and vastly more complex way to do what the .htaccess 
files will do anyway.




> Q2)  What's a good first book for php?
PHP is so much a stock procedural language with a bolt on OO part that 
its hardly worth having a 'first' book in PHP. Essentially if you have 
programmed in anything else, PHP is pretty much like C or Pascal in 
terms of its structure. The differences are subtle, in the (lack of) 
typing and in what libraries are available, and here the online manual 
is the best resource of all, especially user contributed solutions and 
issues.


-- 
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to 
lead are elected by the least capable of producing, and where the 
members of society least likely to sustain themselves or succeed, are 
rewarded with goods and services paid for by the confiscated wealth of a 
diminishing number of producers.

[toc] | [prev] | [next] | [standalone]


#8661 — Re: where to put the binaries was Re: getting perl and php to talk to each other

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-03-14 08:04 -0400
SubjectRe: where to put the binaries was Re: getting perl and php to talk to each other
Message-ID<khse97$ol2$1@dont-email.me>
In reply to#8652
On 3/14/2013 6:11 AM, Cal Dershowitz wrote:
> On 03/07/2013 12:43 PM, The Natural Philosopher wrote:
>
>> a passing familiarity with package management is not a requirement for
>> running PHP or posting in this NG.
>>
>> NOr is installation of php development files and utilities a requirement
>> fora basic LAMP setup.
>>
>>
>
> NP, I've been reading you for a while now.  Did you give me the name of
> a newsgroup where they consider webstuff ontopic?
>

comp.lang.php is on topic for PHP, which drives a lot of websites.  But 
we already know you're an idiot.


> I'm rather convinced that scripting languages are my meal ticket this
> month, so much so that I'm making it happen with my rudimentary
> webtools.  This is what I call output:
>

No, scripting languages seen to be beyond your level of comprehension. 
You're in the same league as TNP.

> http://merrillpjensen.com/food_4.html
>
> This is a powerful medium, where one can intermix binaries and text.  My
> problem now is that it's not a discrete medium without me attending
> endlessly to obfuscations with files that I would much just rather have
> as themselves, and the only way you can see them is if php lets you with
> an authentication level equal to my level of give a crap.
>

Obfuscation is not security!

<snip unrelated crap from an idiot>

>
> This has so far been my home-cooked perl version of static web dev, but
> I want to see if php can obviate all the go***a%n filing-about that you
> have to do to maintain the privacies of the the binaries shown.  These
> images are my shack so I don't care so much anymore.  I also use this
> tool chain to lay down the law with people a bit; it's a very direct
> medium:
>

Sure you can do it with PHP.  But you can do it with perl, also, without 
all the crap.  You just need to understand some basic concepts.

> http://merrillpjensen.com/cleaning_1.html
>
> Q1)  How do I design a website where the binaries aren't there for the
> taking unless php thinks you have done some act of authentication to see
> them?
>

Security measures will prevent users from accessing the files.  But 
you've already said you don't want help, so why do you continue posting?

> Q2)  What's a good first book for php?

Dick and Jane Create a Web Site would be about your speed.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#8527

FromCaptain Paralytic <paul_lautman@yahoo.com>
Date2013-03-04 02:45 -0800
Message-ID<2da82d4e-a1f6-4645-860e-c22793ccfaa4@r9g2000vbh.googlegroups.com>
In reply to#8512
On Mar 1, 1:49 am, Cal Dershowitz <c...@example.invalid> wrote:
> Hello ng,
>
> I've got a working localhost and a couple php scripts that run so far,
> so I wanted to see what types of things I can do and cannot do.  This is
> by no means clear to me to me now.
>
> What I have is a collection of my own music files that I have put in the
> path of where localhost is looking for things; with my default install,
> that is /var/www.
>
> I wrote a bash script to export the files off my mp3 player, because
> neither my gf nor I who bought these things can figure how to make them
> play randomly.  Yes we have achieved a certain age, where determination
> makes up for a lot.
>
> $ cat music1.sh
> #!/bin/bash
>
> set -e
> FROM='CCE0-705F'
> DIR='music1'
> mkdir -p $DIR
> cp  $FROM/*.wma $DIR/
> cp  $FROM/*.mp3 $DIR/
> cd $DIR
> ls -l
> exit 0
> $
>
> So does php have a way to do this that is as simple as it might be in
> perl, for example?
> --
> Cal

Do you know what order the mp3 player uses to decide the order of
play? If for instance it plays in alphabetical order of file name,
then the only way to get them played randomly is to rename them. On
the other hand it could be based on the order in which they are copied
to the device.

[toc] | [prev] | [next] | [standalone]


#8654

FromCal Dershowitz <cal@example.invalid>
Date2013-03-14 03:39 -0700
Message-ID<r_OdnbJOFYF3NdzMnZ2dnUVZ_qGdnZ2d@supernews.com>
In reply to#8527
On 03/04/2013 02:45 AM, Captain Paralytic wrote:
> On Mar 1, 1:49 am, Cal Dershowitz <c...@example.invalid> wrote:
>> Hello ng,
>>
>> I've got a working localhost and a couple php scripts that run so far,
>> so I wanted to see what types of things I can do and cannot do.  This is
>> by no means clear to me to me now.
>>
>> What I have is a collection of my own music files that I have put in the
>> path of where localhost is looking for things; with my default install,
>> that is /var/www.
>>
>> I wrote a bash script to export the files off my mp3 player, because
>> neither my gf nor I who bought these things can figure how to make them
>> play randomly.  Yes we have achieved a certain age, where determination
>> makes up for a lot.
>>
>> $ cat music1.sh
>> #!/bin/bash
>>
>> set -e
>> FROM='CCE0-705F'
>> DIR='music1'
>> mkdir -p $DIR
>> cp  $FROM/*.wma $DIR/
>> cp  $FROM/*.mp3 $DIR/
>> cd $DIR
>> ls -l
>> exit 0
>> $
>>
>> So does php have a way to do this that is as simple as it might be in
>> perl, for example?
>> --
>> Cal
>
> Do you know what order the mp3 player uses to decide the order of
> play? If for instance it plays in alphabetical order of file name,
> then the only way to get them played randomly is to rename them. On
> the other hand it could be based on the order in which they are copied
> to the device.
>

there's a USER.PL there, empty.

playlist perl Idunno.
-- 
Cal

[toc] | [prev] | [standalone]


Page 3 of 3 — ← Prev page 1 2 [3]

Back to top | Article view | comp.lang.php


csiph-web