php-general Digest 1 Dec 2009 13:07:03 -0000 Issue 6467
Topics (messages 300167 through 300175):
Re: Storing (html and php) Content in MySQL - help
300167 by: John List
300168 by: LinuxManMikeC
Object of class stdClass could not be converted to string
300169 by: John Taylor-Johnston
300170 by: LinuxManMikeC
Can I get the IP address from a visitor?
300171 by: Lars Kristiansson
300172 by: Jason
300173 by: Lester Caine
300174 by: Ali Asghar Toraby Parizy
300175 by: Olav
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 ---
Allen McCabe wrote:
I have been trying to wrap my mind around how to accomplish this for a few
days, and done estensive searching on Google.
I know there are free CMS systems available for download, but I want to
write my own code so I can maintain it and extend it, I need it to be
customizable.
So far what I have worked up is this:
The mysql row contains a page_id field, title field, content field, and
sidebar content field.
in index.php:
include("module.php")
$username = findLoggedinUsername()
eval ($content)
in module.php:
$result = mysqlquery("select * from content where page_id = get['id']")
$row = fetcharray9$result)
$content = $row['content']
$title = $row['title']
etc.
The content mysql field contains:
$ct = <<<END
<p>Welcome $username, to the interweb</p>
END;
echo $ct
In the heredoc, I can use variables like $username, but not like
$row['username'].
So far this method works just fine, however I want to be able to edit the
content through the website itself. Am I on the right track or is this
awkward? I am implementing a new, login system (mine isn't secure enough)
and I want to implement it correctly.
How should I go about storing content (which may or may not include php)
into a page content field?
You are definitely trying to reinvent the wheel.
But, having done that myself, I can tell you very generally how I did it.
My content table allowed for multiple rows for each page. Each row had a
label and value (e.g. body:Hello World, sidebar:Goodbye World). To allow
for php code, I added a "type" to each row. (e.g. body:text:Hello World,
sidebar:eval:echo 'Goodbye World';). A template then would have a
function call at the appropriate places to parse the expected content
elements.
As things go, it got a little more complex than that, and then a little
more complex than that, etc.
It's been working fine for me for five or six years and is still
reasonably elegant. I've thought of open sourcing it, but I have a hunch
there are several hundred systems like that already.
Good luck and have fun.
John
--- End Message ---
--- Begin Message ---
On Mon, Nov 30, 2009 at 5:52 PM, Allen McCabe <[email protected]> wrote:
> I have been trying to wrap my mind around how to accomplish this for a few
> days, and done estensive searching on Google.
>
> I know there are free CMS systems available for download, but I want to
> write my own code so I can maintain it and extend it, I need it to be
> customizable.
>
> So far what I have worked up is this:
>
> The mysql row contains a page_id field, title field, content field, and
> sidebar content field.
>
> in index.php:
> include("module.php")
> $username = findLoggedinUsername()
>
> eval ($content)
>
>
> in module.php:
> $result = mysqlquery("select * from content where page_id = get['id']")
> $row = fetcharray9$result)
> $content = $row['content']
> $title = $row['title']
>
> etc.
>
> The content mysql field contains:
>
> $ct = <<<END
> <p>Welcome $username, to the interweb</p>
> END;
>
> echo $ct
>
>
> In the heredoc, I can use variables like $username, but not like
> $row['username'].
>
> So far this method works just fine, however I want to be able to edit the
> content through the website itself. Am I on the right track or is this
> awkward? I am implementing a new, login system (mine isn't secure enough)
> and I want to implement it correctly.
>
> How should I go about storing content (which may or may not include php)
> into a page content field?
>
Use curly braces around the variable within the string when using arrays.
http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex
echo "Hello {$row['username']}";
However, know that string variable parsing can be very inefficient and
consider this analysis of PHP internals in your design.
http://blog.libssh2.org/index.php?/archives/28-How-long-is-a-piece-of-string.html
On small sites with low traffic it doesn't matter much, but as
complexity and usage grows so does the overhead of writing your code
the "easy" way.
--- End Message ---
--- Begin Message ---
Good grief. It doesn't like printing an INT field like as if it were a
string??
I looked at: http://php.ca/manual-lookup.php?pattern=stringtoint like I
might of in Delphi :)p
echo " <td>$mydata->2010</td>\n";
echo " <td>$mydata->2009</td>\n";
Is this something new in PHP? Geez.
John
--- End Message ---
--- Begin Message ---
On Mon, Nov 30, 2009 at 10:27 PM, John Taylor-Johnston
<[email protected]> wrote:
> Good grief. It doesn't like printing an INT field like as if it were a
> string??
>
> I looked at: http://php.ca/manual-lookup.php?pattern=stringtoint like I
> might of in Delphi :)p
>
> echo " <td>$mydata->2010</td>\n";
> echo " <td>$mydata->2009</td>\n";
>
> Is this something new in PHP? Geez.
> John
>
http://www.php.net/manual/en/language.variables.basics.php
http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex
Ever consider actually learning the language?
--- End Message ---
--- Begin Message ---
Hi!
This is probably the wrong forum. Please redirect me if im out of place.
I would like to find out what IP address my visitor uses when visiting a php
script page on my domain. This page would contain a form in which the
visitor would state his/her message.
My goal is to create purchase-orders written on unique files, and to
separate them my idea was to baptize files with the IP addresses, which
would ive each visitor an unique purchase-order...
Any hints to a newbie?
Cheers, Lars
--- End Message ---
--- Begin Message ---
That would be in one of the $_SERVER[] variables.
Look here for more info:
http://uk.php.net/manual/en/reserved.variables.server.php
HTH
J
-----Original Message-----
From: Lars Kristiansson [mailto:[email protected]]
Sent: 30 November 2009 23:47
To: [email protected]
Subject: [PHP] Can I get the IP address from a visitor?
Hi!
This is probably the wrong forum. Please redirect me if im out of place.
I would like to find out what IP address my visitor uses when visiting a php
script page on my domain. This page would contain a form in which the
visitor would state his/her message.
My goal is to create purchase-orders written on unique files, and to
separate them my idea was to baptize files with the IP addresses, which
would ive each visitor an unique purchase-order...
Any hints to a newbie?
Cheers, Lars
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Lars Kristiansson wrote:
Hi!
This is probably the wrong forum. Please redirect me if im out of place.
I would like to find out what IP address my visitor uses when visiting a
php script page on my domain. This page would contain a form in which
the visitor would state his/her message.
My goal is to create purchase-orders written on unique files, and to
separate them my idea was to baptize files with the IP addresses, which
would ive each visitor an unique purchase-order...
Any hints to a newbie?
http://uk3.php.net/manual/en/reserved.variables.server.php
'REMOTE_ADDR'
But don't rely on it to be the same each time for a customer. If they are on a
shared connection then the ISP may give them a different IP each time they
access the internet.
--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php
--- End Message ---
--- Begin Message ---
It is very simple:
$ip=$_SERVER['REMOTE_ADDR'];
On Tue, Dec 1, 2009 at 1:47 PM, Lester Caine <[email protected]> wrote:
> Lars Kristiansson wrote:
>>
>> Hi!
>>
>> This is probably the wrong forum. Please redirect me if im out of place.
>>
>> I would like to find out what IP address my visitor uses when visiting a
>> php script page on my domain. This page would contain a form in which the
>> visitor would state his/her message.
>>
>> My goal is to create purchase-orders written on unique files, and to
>> separate them my idea was to baptize files with the IP addresses, which
>> would ive each visitor an unique purchase-order...
>>
>> Any hints to a newbie?
>
> http://uk3.php.net/manual/en/reserved.variables.server.php
> 'REMOTE_ADDR'
>
> But don't rely on it to be the same each time for a customer. If they are on
> a shared connection then the ISP may give them a different IP each time they
> access the internet.
>
> --
> Lester Caine - G8HFL
> -----------------------------
> Contact - http://lsces.co.uk/wiki/?page=contact
> L.S.Caine Electronic Services - http://lsces.co.uk
> EnquirySolve - http://enquirysolve.com/
> Model Engineers Digital Workshop - http://medw.co.uk//
> Firebird - http://www.firebirdsql.org/index.php
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Lars Kristiansson wrote:
[..]
> My goal is to create purchase-orders written on unique files, and to
> separate them my idea was to baptize files with the IP addresses, which
> would ive each visitor an unique purchase-order...
>
> Any hints to a newbie?
Yes. Do NOT use IP adresses as identifiers. Just forget about it.
People share connections, e.g. when they are in the same building or when
they are using the same proxy. People use domestic/consumer internet
connections that have dynamic IP addresses. Identifying people by their
IP address is therefore stupid.
If it is just to have a key to some data, you could try using a GUID. And
check when you generate one that it doesn't already exist (though the
chance is extremely small, it is not zero). Or just use some serial
number like everyone else does ;)
It may look boring to make files like order0001, order0002 etc. But it
works.
Any reason you are not storing your orders in a database?
--- End Message ---