php-general Digest 28 Aug 2007 23:25:58 -0000 Issue 4987
Topics (messages 261403 through 261430):
Re: Trying to understand sessions and using them to authenticate...
261403 by: Jason Pruim
261404 by: Jason Pruim
261405 by: Daniel Brown
261407 by: Daniel Brown
261408 by: Jason Pruim
261409 by: Stut
261410 by: Daniel Brown
Re: why?
261406 by: Jay Blanchard
261416 by: mike
261417 by: Jay Blanchard
261418 by: Stut
261420 by: mike
261422 by: shiplu
c++ and php! search for a brigde
261411 by: dwa
261414 by: Simon
261415 by: David Giragosian
261419 by: Gevorg Harutyunyan
261421 by: shiplu
261426 by: Jim Lucas
sybase installation error
261412 by: Melanie Pfefer
Re: Database includes
261413 by: brian
Re: Regular expression - URL validator
261423 by: Wagner Garcia Campagner
261424 by: shiplu
261425 by: Jim Lucas
Building Web Site with Member Area in PHP (and MySQL) - Howto
261427 by: Stephen
261428 by: Jay Blanchard
261429 by: Greg Donald
Re: Disadvantages of output buffering
261430 by: Felipe Alcacibar
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
On Aug 24, 2007, at 12:15 PM, Daniel Brown wrote:
On 8/24/07, Jason Pruim <[EMAIL PROTECTED]> wrote:
Hi Everyone,
I'm attempting to figure out the proper way to use sessions to log
someone into my system. The idea being, if they arn't logged in all
they can see is the login form, and if they are logged in, they and
have access to a database of addresses.
[snip!]
Not the end-all-be-all, of course, but here's the basics:
<?
session_start();
if(!$_SESSION['user']) {
if($_POST['user'] && $_POST['pass']) { // Keep in mind, PASSWORD
has meaning in MySQL
// Do your string sanitizing here
// (e.g. - $user = mysql_real_escape_string($_POST['user']);)
$sql = "SELECT * FROM users WHERE user='".$user."' AND
pass='".$pass."' LIMIT 0,1;";
$result = mysql_query($sql) or die("Wrong data supplied or
database error");
while($row = mysql_fetch_array($result)) {
$_SESSION['user'] = $row['user'];
// Do whatever else you need to do here....
}
} else {
// Show your login form here.
}
} else {
// The user is authenticated and logged in already.
}
?>
Keep in mind that, as always, this hasn't been bug-checked,
re-read, or otherwise validated.
Hey Dan,
Thanks for the response, I think I see and understand what you are
trying to say in there, but I am hitting a road block now... It won't
display the page. I have tried to both just include the page, and
copied the entire page and pasted it in the proper location.
Any ideas? Here's the code... And no I still haven't added
mysql_real_escape_string yet... Want to get 1 part working at a
time :) Fewer issues in my head then.
<?PHP
include 'defaults.php';
include 'dbconnect.php';
session_start();
if(!$_SESSION['user']) {
if($_POST['user'] && $_POST['pass']) { // Keep in mind, PASSWORD
has meaning in MySQL
// Do your string sanitizing here
// (e.g. - $user = mysql_real_escape_string($_POST['user']);)
$sql = "SELECT * FROM login WHERE loginid='".$user."' AND
email='".$pass."' LIMIT 0,1;";
$result = mysql_query($sql) or die("Wrong data supplied or
database error");
while($row = mysql_fetch_array($result)) {
$_SESSION['user'] = $row['user'];
// Do whatever else you need to do here....
echo "First Part";
include "index.php";
}
} else {
// Show your login form here.
echo "
<form method=\"post\">
Username : <input type=\"text\" name=\"user\"><br />
Password : <input type=\"password\" name=\"pass\"><br />
<input type=\"submit\" value=\"Login\">
</form>";
echo "Second Part";
}
} else {
// The user is authenticated and logged in already.
echo "Just before include";
include "index.php";
echo "Third part";
}
?>
The few echo's that are in there are only there for debugging, easier
to see how far I get :)
Thanks for looking! :)
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]
--- End Message ---
--- Begin Message ---
On Aug 28, 2007, at 10:03 AM, Daniel Brown wrote:
On 8/28/07, Jason Pruim <[EMAIL PROTECTED]> wrote:
[snip]
$sql = "SELECT * FROM users WHERE user='".$user."' AND
pass='".$pass."' LIMIT 0,1;";
$result = mysql_query($sql) or die("Wrong data supplied or
database error");
while($row = mysql_fetch_array($result)) {
Sounds to me like you're not getting through the while() clause,
meaning that there's no matching rows in the database.
$sql = "SELECT * FROM login WHERE loginid='".$user."' AND
email='".$pass."' LIMIT 0,1;";
Is the password they supply in the `email` column of the database?
Yes it is... For now... I am just using test/test and I had a field
named password in the database but thought that was messing it up, so
I dropped that field and currently I am just using the e-mail field
as a password.
Once it works I'll change the field to a more appropriate selection
with MD5 hashing, and maybe even a little salt in the hash. (Gotta
add the flavor!)
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]
--- End Message ---
--- Begin Message ---
On 8/28/07, Jason Pruim <[EMAIL PROTECTED]> wrote:
[snip]
> > $sql = "SELECT * FROM users WHERE user='".$user."' AND
> > pass='".$pass."' LIMIT 0,1;";
> > $result = mysql_query($sql) or die("Wrong data supplied or
> > database error");
> > while($row = mysql_fetch_array($result)) {
Sounds to me like you're not getting through the while() clause,
meaning that there's no matching rows in the database.
$sql = "SELECT * FROM login WHERE loginid='".$user."' AND
email='".$pass."' LIMIT 0,1;";
Is the password they supply in the `email` column of the database?
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
Hey, PHP-General list....
50% off for life on web hosting plans $10/mo. or more at
http://www.pilotpig.net/.
Use the coupon code phpgeneralaug07
Register domains for about $0.01 more than what it costs me at
http://domains.pilotpig.net/.
--- End Message ---
--- Begin Message ---
On 8/28/07, Jason Pruim <[EMAIL PROTECTED]> wrote:
>
> On Aug 28, 2007, at 10:03 AM, Daniel Brown wrote:
>
> > On 8/28/07, Jason Pruim <[EMAIL PROTECTED]> wrote:
> > [snip]
> >>> $sql = "SELECT * FROM users WHERE user='".$user."' AND
> >>> pass='".$pass."' LIMIT 0,1;";
> >>> $result = mysql_query($sql) or die("Wrong data supplied or
> >>> database error");
> >>> while($row = mysql_fetch_array($result)) {
> >
> > Sounds to me like you're not getting through the while() clause,
> > meaning that there's no matching rows in the database.
> >
> > $sql = "SELECT * FROM login WHERE loginid='".$user."' AND
> > email='".$pass."' LIMIT 0,1;";
> >
> > Is the password they supply in the `email` column of the database?
>
> Yes it is... For now... I am just using test/test and I had a field
> named password in the database but thought that was messing it up, so
> I dropped that field and currently I am just using the e-mail field
> as a password.
>
> Once it works I'll change the field to a more appropriate selection
> with MD5 hashing, and maybe even a little salt in the hash. (Gotta
> add the flavor!)
>
>
> --
>
> Jason Pruim
> Raoset Inc.
> Technology Manager
> MQC Specialist
> 3251 132nd ave
> Holland, MI, 49424
> www.raoset.com
> [EMAIL PROTECTED]
>
>
>
If you have phpMyAdmin installed on that server, J, try using the
"search" tab to see if you can find that user/email combination in the
database using = and not LIKE.
Perhaps there's a whitespace or something of the like that's
causing it to return zero rows.
Also, try doing this after the $result = mysql_query($sql); line:
die("Number of rows returned by MySQL: ".mysql_num_rows($result));
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
Hey, PHP-General list....
50% off for life on web hosting plans $10/mo. or more at
http://www.pilotpig.net/.
Use the coupon code phpgeneralaug07
Register domains for about $0.01 more than what it costs me at
http://domains.pilotpig.net/.
--- End Message ---
--- Begin Message ---
On Aug 28, 2007, at 10:21 AM, Daniel Brown wrote:
On 8/28/07, Jason Pruim <[EMAIL PROTECTED]> wrote:
On Aug 28, 2007, at 10:03 AM, Daniel Brown wrote:
On 8/28/07, Jason Pruim <[EMAIL PROTECTED]> wrote:
[snip]
$sql = "SELECT * FROM users WHERE user='".$user."' AND
pass='".$pass."' LIMIT 0,1;";
$result = mysql_query($sql) or die("Wrong data supplied or
database error");
while($row = mysql_fetch_array($result)) {
Sounds to me like you're not getting through the while() clause,
meaning that there's no matching rows in the database.
$sql = "SELECT * FROM login WHERE loginid='".$user."' AND
email='".$pass."' LIMIT 0,1;";
Is the password they supply in the `email` column of the
database?
Yes it is... For now... I am just using test/test and I had a field
named password in the database but thought that was messing it up, so
I dropped that field and currently I am just using the e-mail field
as a password.
Once it works I'll change the field to a more appropriate selection
with MD5 hashing, and maybe even a little salt in the hash. (Gotta
add the flavor!)
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]
If you have phpMyAdmin installed on that server, J, try using the
"search" tab to see if you can find that user/email combination in the
database using = and not LIKE.
Perhaps there's a whitespace or something of the like that's
causing it to return zero rows.
Also, try doing this after the $result = mysql_query($sql); line:
die("Number of rows returned by MySQL: ".mysql_num_rows
($result));
I don't have phpMyAdmin installed, never saw the need to... But I'll
look into it in the future.
And after adding the die that you recommended, you were right, it
wasn't returning any rows. So... I did some checking and it's amazing
sometimes that you can't see the trees through the forrest.... a
simple $user =$_POST['user']; and $pass=$_POST['pass']; and all is
well. It logs into the page, now I just need to fine tune it since it
doesn't like to display the actual database now, but that's something
I should be able to figure out.
One other question, to logout, can I just call a file that has
session_destroy() and a header("Location: ???"); in it? Or should I
do something else for logging out?
Thanks again! Without your help... I wouldn't be able to do this!
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]
--- End Message ---
--- Begin Message ---
Jason Pruim wrote:
One other question, to logout, can I just call a file that has
session_destroy() and a header("Location: ???"); in it? Or should I do
something else for logging out?
foreach (array_keys($_SESSION) as $key)
unset($_SESSION[$key];
session_destroy();
-Stut
--
http://stut.net/
--- End Message ---
--- Begin Message ---
On 8/28/07, Jason Pruim <[EMAIL PROTECTED]> wrote:
>
> On Aug 28, 2007, at 10:21 AM, Daniel Brown wrote:
>
> > On 8/28/07, Jason Pruim <[EMAIL PROTECTED]> wrote:
> >>
> >> On Aug 28, 2007, at 10:03 AM, Daniel Brown wrote:
> >>
> >>> On 8/28/07, Jason Pruim <[EMAIL PROTECTED]> wrote:
> >>> [snip]
> >>>>> $sql = "SELECT * FROM users WHERE user='".$user."' AND
> >>>>> pass='".$pass."' LIMIT 0,1;";
> >>>>> $result = mysql_query($sql) or die("Wrong data supplied or
> >>>>> database error");
> >>>>> while($row = mysql_fetch_array($result)) {
> >>>
> >>> Sounds to me like you're not getting through the while() clause,
> >>> meaning that there's no matching rows in the database.
> >>>
> >>> $sql = "SELECT * FROM login WHERE loginid='".$user."' AND
> >>> email='".$pass."' LIMIT 0,1;";
> >>>
> >>> Is the password they supply in the `email` column of the
> >>> database?
> >>
> >> Yes it is... For now... I am just using test/test and I had a field
> >> named password in the database but thought that was messing it up, so
> >> I dropped that field and currently I am just using the e-mail field
> >> as a password.
> >>
> >> Once it works I'll change the field to a more appropriate selection
> >> with MD5 hashing, and maybe even a little salt in the hash. (Gotta
> >> add the flavor!)
> >>
> >>
> >> --
> >>
> >> Jason Pruim
> >> Raoset Inc.
> >> Technology Manager
> >> MQC Specialist
> >> 3251 132nd ave
> >> Holland, MI, 49424
> >> www.raoset.com
> >> [EMAIL PROTECTED]
> >>
> >>
> >>
> >
> > If you have phpMyAdmin installed on that server, J, try using the
> > "search" tab to see if you can find that user/email combination in the
> > database using = and not LIKE.
> >
> > Perhaps there's a whitespace or something of the like that's
> > causing it to return zero rows.
> >
> > Also, try doing this after the $result = mysql_query($sql); line:
> >
> > die("Number of rows returned by MySQL: ".mysql_num_rows
> > ($result));
>
> I don't have phpMyAdmin installed, never saw the need to... But I'll
> look into it in the future.
>
> And after adding the die that you recommended, you were right, it
> wasn't returning any rows. So... I did some checking and it's amazing
> sometimes that you can't see the trees through the forrest.... a
> simple $user =$_POST['user']; and $pass=$_POST['pass']; and all is
> well. It logs into the page, now I just need to fine tune it since it
> doesn't like to display the actual database now, but that's something
> I should be able to figure out.
>
> One other question, to logout, can I just call a file that has
> session_destroy() and a header("Location: ???"); in it? Or should I
> do something else for logging out?
>
> Thanks again! Without your help... I wouldn't be able to do this!
>
> --
>
> Jason Pruim
> Raoset Inc.
> Technology Manager
> MQC Specialist
> 3251 132nd ave
> Holland, MI, 49424
> www.raoset.com
> [EMAIL PROTECTED]
>
>
>
For my purposes, I simply do a session_destroy();, but some people
may prefer to do an unset for their own purposes.
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
Hey, PHP-General list....
50% off for life on web hosting plans $10/mo. or more at
http://www.pilotpig.net/.
Use the coupon code phpgeneralaug07
Register domains for about $0.01 more than what it costs me at
http://domains.pilotpig.net/.
--- End Message ---
--- Begin Message ---
[snip]
Yes, a single sign-on it is... It doesn't work together with Windows
(and
PHP) you mean?
[/snip]
No, not really.
You can run PHP on a Linux or a Windows server and it does not have
access to the initial login values (press cntl alt del to login)
although ASP and .Net (auth_user, etc) do. This is something that I have
wanted to do for years and we have even discussed on this list.
The initial login has to be configured so that the computer is
accessible either online or off and it can be either basic (plain text)
or challenge/response (encrypted). If it is online it will typically
look at an Active Directory server for authentication using LDAP as the
method of communication. If it is offline the login will typically look
at registry settings to determine if the login is authorized.
Since PHP cannot read registry settings (neither can JavaScript) on the
client that is out. Windows is aware of the logged in user, but exactly
where that 'session' information is kept is a mystery to most of us. So
PHP cannot be aware of a user who has performed the initial login.
What we shoot for is Single Source Authentication. SSA uses LDAP to
connect to AD for authentication purposes. It requires that the user
login to each application, but since we are using the same
authentication platform (within a corporate system) their username and
password combo is the same as their initial login. If they change their
password (which we can make them do on a regular basis using AD's
password policies or they can do on their own -- we can also enforce
password strength) then they are able to continue using the new password
throughout the applications.
This is a very high level overview and it doesn't even begin to talk
about role or group management, but it is how we mitigate the
username/password issue for corporate users. For a public web site the
method may be quite a bit different.
--- End Message ---
--- Begin Message ---
On 8/28/07, Jay Blanchard <[EMAIL PROTECTED]> wrote:
> Since PHP cannot read registry settings (neither can JavaScript) on the
> client that is out. Windows is aware of the logged in user, but exactly
> where that 'session' information is kept is a mystery to most of us. So
> PHP cannot be aware of a user who has performed the initial login.
i know there is an apache NTLM(1) module for this. i don't believe it
requires anything other than a connection to a domain authentication
server and the ability to send headers and read the reply
(challenge/response) - i don't think the registry is needed at all on
the client or the server.
(1) http://modntlm.sourceforge.net/ - just one example
--- End Message ---
--- Begin Message ---
[snip]
i know there is an apache NTLM(1) module for this. i don't believe it
requires anything other than a connection to a domain authentication
server and the ability to send headers and read the reply
(challenge/response) - i don't think the registry is needed at all on
the client or the server.
(1) http://modntlm.sourceforge.net/ - just one example
[/snip]
True, but it appears that many of these are not ready for prime time and
require an extensive amount of configuration (sometimes even modifying
the registry).
--- End Message ---
--- Begin Message ---
Jay Blanchard wrote:
[snip]
i know there is an apache NTLM(1) module for this. i don't believe it
requires anything other than a connection to a domain authentication
server and the ability to send headers and read the reply
(challenge/response) - i don't think the registry is needed at all on
the client or the server.
(1) http://modntlm.sourceforge.net/ - just one example
[/snip]
True, but it appears that many of these are not ready for prime time and
require an extensive amount of configuration (sometimes even modifying
the registry).
In addition the OP is running IIS so this is all kinda less than helpful
to him.
-Stut
--
http://stut.net/
--- End Message ---
--- Begin Message ---
On 8/28/07, Stut <[EMAIL PROTECTED]> wrote:
> In addition the OP is running IIS so this is all kinda less than helpful
> to him.
yeah, i didn't say this would, but it should be able to be ported to a
PHP module by someone i would think. i mean if someone can do it in
Perl or C (especially C) why can't it just be changed to work under
zend/etc?
--- End Message ---
--- Begin Message ---
On 8/28/07, mike <[EMAIL PROTECTED]> wrote:
>
> On 8/28/07, Stut <[EMAIL PROTECTED]> wrote:
> > In addition the OP is running IIS so this is all kinda less than helpful
> > to him.
>
> yeah, i didn't say this would, but it should be able to be ported to a
> PHP module by someone i would think. i mean if someone can do it in
> Perl or C (especially C) why can't it just be changed to work under
> zend/etc?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
This topics subject ("Why?") is not related. I thinks its better to change
it and create another thread. it'll be better for other who already doesn't
know what the actual topic is.
Thanks :)
--
shout at http://shiplu.awardspace.com/
Available for Hire/Contract/Full Time
--- End Message ---
--- Begin Message ---
Hello people,
i have a question??
I have an application written in c++ and this throw real time data as
udp-pakets all the time (interval 1 min and values in a wrapper like an
own protocol are floats and longs).
Is there any possibility to catch the udp packets - parse the pakets und
show the values in tables in a html-doc in real time???
What technologies are good? ajax? cgi? ive no idea!!!!!
mfg
david
--- End Message ---
--- Begin Message ---
you can use sockets in php, they work the same as berkley sockets
you can use system() in php, to call your C++ program (the program
could output html)
in my opinon CGI with C/C++ is obsolete, use php/apache for best results!
another nice way is to have your C++ program independent, outputs its
results/values into a database (mysql)... and a php page will just
read what's in the database to display it nicely.
That would be a clean way of doing it.
Good luck!
--- End Message ---
--- Begin Message ---
On 8/28/07, Simon <[EMAIL PROTECTED]> wrote:
>
> you can use sockets in php, they work the same as berkley sockets
> you can use system() in php, to call your C++ program (the program
> could output html)
> in my opinon CGI with C/C++ is obsolete, use php/apache for best results!
>
> another nice way is to have your C++ program independent, outputs its
> results/values into a database (mysql)... and a php page will just
> read what's in the database to display it nicely.
That's what we do here. C/C++ app gathers and inserts the data into the db,
minute by minute, and PHP apps are used for display, reports, graphics,
etc... Our LAMP system has had nary a glitch in over 3 years of continuous
usage.
That would be a clean way of doing it.
>
> Good luck!
David
--- End Message ---
--- Begin Message ---
Barev David,
I think this is solution
1. C/C++ updates database (MySQL or other)
2. There is some PHP file that is viewing your DB info(printing static info)
3. There is other PHP file that is using AJAX for interactive update of
information (This one is sending request to first PHP file and if needed
updating second one)
I don't know maybe this is very complex, but I would choose this one ;)
Best,
Gevorg
-----Original Message-----
From: David Giragosian [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 28, 2007 10:08 PM
To: Simon
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] c++ and php! search for a brigde
On 8/28/07, Simon <[EMAIL PROTECTED]> wrote:
>
> you can use sockets in php, they work the same as berkley sockets
> you can use system() in php, to call your C++ program (the program
> could output html)
> in my opinon CGI with C/C++ is obsolete, use php/apache for best results!
>
> another nice way is to have your C++ program independent, outputs its
> results/values into a database (mysql)... and a php page will just
> read what's in the database to display it nicely.
That's what we do here. C/C++ app gathers and inserts the data into the db,
minute by minute, and PHP apps are used for display, reports, graphics,
etc... Our LAMP system has had nary a glitch in over 3 years of continuous
usage.
That would be a clean way of doing it.
>
> Good luck!
David
--- End Message ---
--- Begin Message ---
On 8/28/07, Gevorg Harutyunyan <[EMAIL PROTECTED]> wrote:
>
> Barev David,
>
> I think this is solution
>
> 1. C/C++ updates database (MySQL or other)
> 2. There is some PHP file that is viewing your DB info(printing static
> info)
> 3. There is other PHP file that is using AJAX for interactive update of
> information (This one is sending request to first PHP file and if needed
> updating second one)
>
> I don't know maybe this is very complex, but I would choose this one ;)
>
> Best,
> Gevorg
>
> -----Original Message-----
> From: David Giragosian [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, August 28, 2007 10:08 PM
> To: Simon
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PHP] c++ and php! search for a brigde
>
> On 8/28/07, Simon <[EMAIL PROTECTED]> wrote:
> >
> > you can use sockets in php, they work the same as berkley sockets
> > you can use system() in php, to call your C++ program (the program
> > could output html)
> > in my opinon CGI with C/C++ is obsolete, use php/apache for best
> results!
> >
> > another nice way is to have your C++ program independent, outputs its
> > results/values into a database (mysql)... and a php page will just
> > read what's in the database to display it nicely.
>
>
> That's what we do here. C/C++ app gathers and inserts the data into the
> db,
> minute by minute, and PHP apps are used for display, reports, graphics,
> etc... Our LAMP system has had nary a glitch in over 3 years of continuous
> usage.
>
> That would be a clean way of doing it.
> >
> > Good luck!
>
>
>
> David
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
No, this is not that tough. we did it before.
1. A C program retrieves data from several (more than 100) servers.
2. It saves the data in the MySQL db.
3. A php page is loaded with an ajax enabled
4. then a ajax call is sent to the same php file. it uses the setTimeout
function.
5. Data comes in json format.
6. data is formated by javascript and shown in the page.
Thats it.
--
shout at http://shiplu.awardspace.com/
Available for Hire/Contract/Full Time
--- End Message ---
--- Begin Message ---
dwa wrote:
Hello people,
i have a question??
I have an application written in c++ and this throw real time data as
udp-pakets all the time (interval 1 min and values in a wrapper like an
own protocol are floats and longs).
Is there any possibility to catch the udp packets - parse the pakets und
show the values in tables in a html-doc in real time???
What technologies are good? ajax? cgi? ive no idea!!!!!
mfg
david
I recently built a PHP daemon. It uses sockets to listen on a given port for
UDP packets.
Take in a request, processes, decides what it needs to do based off the request and then takes
action. Once it is done with said action, starts listening again. This process is done a few times
a second. I have it logging connections to a DB and saving other information to a log file in the
file system.
You could easily take something like this and create a daemon that would listen for incoming
connections and from the data it gets build a page and drop that onto the file system.
here is an example of what I do
<?php
define('LISTEN_IP', 'X.X.X.X'); // IP to listin on '0.0.0.0' would
listen on all IP's
define('LISTEN_PORT', 8080); // Port number to listen on (8080)
define('PACKET_SIZE', 512); // 512 bytes
if ( $socket = @stream_socket_server('udp://'.LISTEN_IP.':'.LISTEN_PORT, $errno, $errstr,
STREAM_SERVER_BIND) ) {
while ( true ) {
$packet = '';
while ( $buff = stream_socket_recvfrom($socket, PACKET_SIZE, 0,
$remote_ip) ) {
$packet .= $buff;
}
// if need be, loop this until you get to the end of your
packet/information
while ( !empty($buff) ) {
$buff = stream_socket_recvfrom($socket, PACKET_SIZE, 0,
$remote_ip);
}
// work with $buff here to capture all your data.
// Then also figure out when and if you need to exit
}
fclose($socket);
}
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
--- End Message ---
--- Begin Message ---
hi,
I am getting an error when I issue 'make' command:
../configure --with-apxs2=/usr/local/apache/bin/apxs
--with-sybase-ct=/opt/sybase/OCS-12_5
it finishes with:
ld: fatal: library -lsybtcl: not found
ld: fatal: File processing errors. No output written
to .libs/libphp5.so
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `libphp5.la'
___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/
--- End Message ---
--- Begin Message ---
Larry Garfield wrote:
On Sunday 26 August 2007, Bruce Cowin wrote:
I'm curious as to how everyone organises and includes their classes in
PHP5.
Then have a config file of some sort in which you specify your DB credentials.
There's a variety of ways to do that (ini file, a PHP file with a database
url, a PHP file that just has a couple of variables in it, or constants
instead, etc.). Pick one you like. Then have your DB connection class read
that file's data one way or another and connect as appropriate.
If you have to modify anything other than a single config file in order to
move your site/app from one server to another, then you have a design flaw.
(I'd say that applies for moving the site to a subdirectory on a server too,
but that takes a bit more effort.)
I'm with Larry on this. Include a constants file at the top of your
scripts. In that file you can place a switch block that tests for the
$_SERVER['HTTP_HOST']. For each case, place something like:
define('DB_NAME', 'my_dev_db');
Other things this is useful for are setting a boolean constant that a
class might test in, eg. a toString method or error handling, and email
addresses for scripts that phone the client. If you have a bunch of
different ones it might be easiest to define dev & test email addresses
first and, in the switch block, set the others accordingly. So, say you
have several email addresses for various things being sent to client
employees (sales@, admin@, jobs@, etc.). You can do something like:
define('EMAIL_DEV', '[EMAIL PROTECTED]');
...
switch($_SERVER['HTTP_HOST'])
{
...
case 'dev.myclient.mycompany.com':
define('MY_APP_DEBUG', TRUE);
define('DB_NAME', 'my_dev_db');
define('EMAIL_SALES', EMAIL_DEV);
define('EMAIL_ADMIN', EMAIL_DEV);
define('EMAIL_JOBS', EMAIL_DEV);
...
break;
No muss. No fuss.
b
--- End Message ---
--- Begin Message ---
Thanks Jim,
Your sugestion worked perfect for me!!
I have another question:
After i validate this URL i want to put a link with this URL in my page.
The problem is that if the URL is like (www.aol.com), when i create the
link, this URL is appended with the URL of my site. The result is a link
pointing to: http://<mywebsite>/www.aol.com
But if the URL is like (http://aol.com), then the link is created correct.
Is there a way to avoid the first situation... so the link is created
correct?
Thanks again,
Wagner.
-----Original Message-----
From: Jim Lucas [mailto:[EMAIL PROTECTED]
Sent: segunda-feira, 27 de agosto de 2007 17:36
To: PHP General; [EMAIL PROTECTED]
Subject: Re: [PHP] Regular expression - URL validator
Wagner Garcia Campagner wrote:
> Hello,
>
> I found this regular expression on a web site.
> It is basicaly an URL validator.
>
> I'm trying to implement this in my web site, but i receive errors.
>
> I think this is a PERL REGEX so what should i do to make it work in php?
>
>
> $valid =
>
(preg_match('^((((H|h)(T|t)|(F|f))(T|t)(P|p)((S|s)?))\://)?(www.|[a-zA-Z0-9]
>
.)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}(\:[0-9]{1,5})*(/($|[a-zA-Z0-9\.\,\;\?\'\\\
> +&%\$#\=~_\-]+))*$', $_POST['website']));
This should be preg_match('/.../i', $_POST['website'])
your regex should look something like this.
^((ftp|(http(s)?))://)?(\.?([a-z0-9-]+))+\.[a-z]{2,6}(:[0-9]{1,5})?(/[a-zA-Z
0-9.,;\?|\'+&%\$#=~_-]+)*$
So, put it all together and it should look like this.
<?php
$url = "...PUT YOUR TEST URL HERE...";
if (
preg_match('!^((ftp|(http(s)?))://)?(\.?([a-z0-9-]+))+\.[a-z]{2,6}(:[0-9]{1,
5})?(/[a-zA-Z0-9.,;\?|\'+&%\$#=~_-]+)*$!i',
$url) ) {
echo "Matched";
} else {
echo "Did not match";
}
>
> if ($valido == 0) {
> something here;
> }
> else {
> something else here;
> }
>
>
> Thanks a lot in advance,
> Wagner.
>
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
--- End Message ---
--- Begin Message ---
On 8/28/07, Wagner Garcia Campagner <[EMAIL PROTECTED]> wrote:
>
> Thanks Jim,
>
> Your sugestion worked perfect for me!!
>
> I have another question:
>
> After i validate this URL i want to put a link with this URL in my page.
>
> The problem is that if the URL is like (www.aol.com), when i create the
> link, this URL is appended with the URL of my site. The result is a link
> pointing to: http://<mywebsite>/www.aol.com
>
> But if the URL is like (http://aol.com), then the link is created correct.
>
> Is there a way to avoid the first situation... so the link is created
> correct?
>
> Thanks again,
> Wagner.
>
>
>
> -----Original Message-----
> From: Jim Lucas [mailto:[EMAIL PROTECTED]
> Sent: segunda-feira, 27 de agosto de 2007 17:36
> To: PHP General; [EMAIL PROTECTED]
> Subject: Re: [PHP] Regular expression - URL validator
>
>
> Wagner Garcia Campagner wrote:
> > Hello,
> >
> > I found this regular expression on a web site.
> > It is basicaly an URL validator.
> >
> > I'm trying to implement this in my web site, but i receive errors.
> >
> > I think this is a PERL REGEX so what should i do to make it work in php?
> >
> >
> > $valid =
> >
>
> (preg_match('^((((H|h)(T|t)|(F|f))(T|t)(P|p)((S|s)?))\://)?(www.|[a-zA-Z0-9]
> >
>
> .)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}(\:[0-9]{1,5})*(/($|[a-zA-Z0-9\.\,\;\?\'\\\
> > +&%\$#\=~_\-]+))*$', $_POST['website']));
>
> This should be preg_match('/.../i', $_POST['website'])
>
> your regex should look something like this.
>
>
> ^((ftp|(http(s)?))://)?(\.?([a-z0-9-]+))+\.[a-z]{2,6}(:[0-9]{1,5})?(/[a-zA-Z
> 0-9.,;\?|\'+&%\$#=~_-]+)*$
>
> So, put it all together and it should look like this.
>
> <?php
>
> $url = "...PUT YOUR TEST URL HERE...";
>
> if (
>
> preg_match('!^((ftp|(http(s)?))://)?(\.?([a-z0-9-]+))+\.[a-z]{2,6}(:[0-9]{1,
> 5})?(/[a-zA-Z0-9.,;\?|\'+&%\$#=~_-]+)*$!i',
> $url) ) {
> echo "Matched";
> } else {
> echo "Did not match";
> }
>
>
>
>
> >
> > if ($valido == 0) {
> > something here;
> > }
> > else {
> > something else here;
> > }
> >
> >
> > Thanks a lot in advance,
> > Wagner.
> >
>
>
>
> --
> Jim Lucas
>
> "Some men are born to greatness, some achieve greatness,
> and some have greatness thrust upon them."
>
> Twelfth Night, Act II, Scene V
> by William Shakespeare
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
you must use http://www.aol.com not www.aol.com. coz the later is not a
valid url. The protocol is not specified there. and if you use
www.aol.comis your href of a tags, the browser will automatically add
your current web
address as prefix as if its a relative url.
if your site is http://www.example.com/folder/site.html
and if you use href="/www.aol.com" it will show http://www.example.com/
www.aol.com
if you use href="www.aol.com" it will show
http://www.example.com/folder/<http://www.aol.com/>
www.aol.com
you have to use href="http://www.aol.com" the absolute one.
--
shout at http://shiplu.awardspace.com/
Available for Hire/Contract/Full Time
--- End Message ---
--- Begin Message ---
Wagner Garcia Campagner wrote:
Thanks Jim,
Your sugestion worked perfect for me!!
I have another question:
After i validate this URL i want to put a link with this URL in my page.
The problem is that if the URL is like (www.aol.com), when i create the
link, this URL is appended with the URL of my site. The result is a link
pointing to: http://<mywebsite>/www.aol.com
But if the URL is like (http://aol.com), then the link is created correct.
Is there a way to avoid the first situation... so the link is created
correct?
Thanks again,
Wagner.
You could always do a string comparison for http(s)? in the url
if ( strpos($url, array('https://', 'http://')) === false ) {
$url = 'http://'.$url;
}
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
--- End Message ---
--- Begin Message ---
Can anyone recommend resources that I can use to learn
about doing this?
Are then any open source scripts that demonstrate this
kind of site?
Thanks
Stephen
--- End Message ---
--- Begin Message ---
[snip]
Can anyone recommend resources that I can use to learn
about doing this?
Are then any open source scripts that demonstrate this
kind of site?
[/snip]
Google is your friend
http://www.google.com/search?hl=en&q=PHP+MySQL+login
--- End Message ---
--- Begin Message ---
On 8/28/07, Jay Blanchard <[EMAIL PROTECTED]> wrote:
> Google is your friend
> http://www.google.com/search?hl=en&q=PHP+MySQL+login
Everyone knows that already, even Google.
http://www.google.com/search?q=google+is+your+friend
--
Greg Donald
http://destiney.com/
--- End Message ---
--- Begin Message ---
Emil Edeholt wrote:
Hi!
My php project would get a much cleaner code if I could set cookies
anywhere in the code. So I thought of output buffering. But I can't find
any articles on the cons of output buffering. I mean it most be a reason
for it being off by default?
Kind Regards Emil Edeholt
The output buffering maybe would be unstable your php application in
some cases. May be it so slowly in some versions of php and depend of
the web server that you have mounted your php. And it uses memory this
point is so clearly.
If you want to create cookies server/client "on the fly" you may need
ajax, with this asynchronus requests you put headers and cookies
instead, and use it on the fly in the browser if the http request is ok.
Are you know the session variables, maybe you need that.
Well, the desicion is yours. tell us what you want to do.
Cheers!!
Felipe Alcacibar
--- End Message ---