php-general Digest 22 Jan 2006 00:22:49 -0000 Issue 3919
Topics (messages 229008 through 229015):
using sessions instead of cookie
229008 by: Ross
229010 by: tedd
229011 by: James Benson
anyone know a good php proxy
229009 by: Geoff
Re: question about using $this as a method in a function argument
229012 by: Bogdan Ribic
Re: Str to Int
229013 by: Rick Emery
Re: what is the session equivalent to setcookie?
229014 by: comex
proc_open and buffer limit?
229015 by: Mark Krenz
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 ---
I have never used sessions before. How do I change the follow from COOKIES
to SESSIONS in php (I do not know how to set a session)...
At present the script uses an iframe with cookies but I believe if I use
sessions I can leave out the iframe.
http://www.ecurry.net/menu.phps
http://www.ecurry.net/order2.phps
The scipt adds a name and count to the cookie array, then works out the
total using the order2 script.
if (isset($add)){
${$food} = intval($_COOKIE['cookie'][$food]);
ob_clean();
$new= $$food+1;
include('names.php');
setcookie("cookie[$food]", "$new $name");
}
;
if (isset($minus)){
${$food} = intval($_COOKIE['cookie'][$food]);
if (${$food} == 0) {
}
else {;
ob_clean();
$new= $$food-1;
include('names.php');
setcookie("cookie[$food]", "$new $name");
}
}
and the order2 script...
if (isset($_COOKIE['cookie'])) {
foreach ($_COOKIE['cookie'] as $name => $quantity) {
if ($name == "pakora") {$sub_total = $sub_total + ($priceA *
$quantity); $pricecode= $priceA; check_zero($quantity, $pricecode);}
if ($name == "haggis_fritter") {$sub_total = $sub_total + ($priceB *
$quantity); $pricecode= $priceB;check_zero($quantity, $pricecode);}
}}
--- End Message ---
--- Begin Message ---
I have never used sessions before. How do I change the follow from COOKIES
to SESSIONS in php (I do not know how to set a session)...
<?php session_start(); ?>
tedd
--
--------------------------------------------------------------------------------
http://sperling.com/
--- End Message ---
--- Begin Message ---
http://php.net/manual/en/ref.session.php
Ross wrote:
I have never used sessions before. How do I change the follow from COOKIES
to SESSIONS in php (I do not know how to set a session)...
At present the script uses an iframe with cookies but I believe if I use
sessions I can leave out the iframe.
http://www.ecurry.net/menu.phps
http://www.ecurry.net/order2.phps
The scipt adds a name and count to the cookie array, then works out the
total using the order2 script.
if (isset($add)){
${$food} = intval($_COOKIE['cookie'][$food]);
ob_clean();
$new= $$food+1;
include('names.php');
setcookie("cookie[$food]", "$new $name");
}
;
if (isset($minus)){
${$food} = intval($_COOKIE['cookie'][$food]);
if (${$food} == 0) {
}
else {;
ob_clean();
$new= $$food-1;
include('names.php');
setcookie("cookie[$food]", "$new $name");
}
}
and the order2 script...
if (isset($_COOKIE['cookie'])) {
foreach ($_COOKIE['cookie'] as $name => $quantity) {
if ($name == "pakora") {$sub_total = $sub_total + ($priceA *
$quantity); $pricecode= $priceA; check_zero($quantity, $pricecode);}
if ($name == "haggis_fritter") {$sub_total = $sub_total + ($priceB *
$quantity); $pricecode= $priceB;check_zero($quantity, $pricecode);}
}}
--
---------------------------------------------------------
http://www.ciwcertified.com - Master CIW Designer
http://www.zend.com - Zend Certified Engineer
http://www.jamesbenson.co.uk
---------------------------------------------------------
--- End Message ---
--- Begin Message ---
Hi all,
Does anyone know of (or have sample code for) a decent PHP proxy?
All I need to do fetch webpages from a remote site, replace certain
trigger text, then return them to the browser.
However, the user's browser must only be aware of my proxy page - it
shouldn't know where the pages are coming from.
Thanks in advance,
Geoff.
--- End Message ---
--- Begin Message ---
>
> I have a question about using $this as an argument in a method.
>
As I understand it, the only issue here is if you are passing $this
from constructor of your class from PHP 4. In short, when you do
$var = new MyClass();
you are actually storing a copy of what constructor was seeing as
$this, and if you passed $this from constructor to an outside function
that stores it somewhere, then you now have two different objects. Way
to circumvent this is to use
$var = & new MyClass();
ie, use a reference, or make sure that your script will be running on
PHP5. If you do the above thing with reference in PHP 5 though, you will
get a warning that this is deprecated.
Hope this helps...
Boban.
--
Open source PHP code generator for DB operations
http://sourceforge.net/projects/bfrcg/
--- End Message ---
--- Begin Message ---
Quoting [EMAIL PROTECTED]:
3. if ($cardID = '' || is_int($cardID))
As someone mentioned, $cardID = '' makes an assignment, doesn't
test for true/false. Change to $cardID == ''. And this statement
SHOULD come up "true" as a whole because $cardID = '' should always
be true (unless the assignment fails). So regardless of
is_int($cardID) succeeding or failing, $cardID = '' should be true
so this statement will always be true.
A trick I read about during my time of learning best practices: if
comparing against a literal or constant, place the literal or constant
on the left side of the expression. For example,
if ('' == $cardID) {
instead of
if ($cardID == '') {
That way, if you accidentally use "=" instead of "==", you should get
an error because you can't assign something to a literal or constant.
Hope this helps somebody,
Rick
--
Rick Emery
"When once you have tasted flight, you will forever walk the Earth
with your eyes turned skyward, for there you have been, and there
you will always long to return"
-- Leonardo Da Vinci
--- End Message ---
--- Begin Message ---
> session_register("cookie[$food]", "$new $name");
$_SESSION['cookie'][$food] = "$new $name";
--- End Message ---
--- Begin Message ---
I'm using PHP 5.1.1 on Apache 2.0.54 on Gentoo Linux. I've been trying
to write a program to pass information to a program using proc_open,
however when I do, it only passes the first 65536 bytes of the stream
and then cuts off the rest. To make sure its not the program I'm trying
to send to, I tries using /bin/cat instead and get the same problem.
Below, I've included the code that I'm using, which for the most part is
from the proc_open documentation page. For testing, I'm reading from a
word dictionary which is over 2MB in size. Is there something I'm
missing about using proc_open?
-------------------------------------------------------------------------
$program = "/bin/cat";
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "/tmp/error-output.txt", "a")
);
$cwd = '/var/www';
$env = array('HOME' => '/var/www');
$process = proc_open($program, $descriptorspec, $pipes, $cwd, $env);
if (is_resource($process)) {
stream_set_blocking($pipes[0], FALSE);
stream_set_blocking($pipes[1], FALSE);
$handle = fopen("/usr/share/dict/words", "r");
while (!feof($handle)) {
$input .= fread($handle, 8192);
}
fwrite($pipes[0], $input);
fclose($handle);
fclose($pipes[0]);
while (!feof($pipes[1])) {
$output .= fgets($pipes[1], 8192);
}
fclose($pipes[1]);
print "<PRE>$output</PRE><BR><BR>\n";
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
-------------------------------------------------------------------------
--
Mark S. Krenz
IT Director
Suso Technology Services, Inc.
http://suso.org/
--- End Message ---