[PHP] Returning values from functions

2003-07-09 Thread Jason Giangrande
I have a function that checks to see if a user has an active session and
if so I'd like it to return the value of a variable (the variable
$username).  However, when I var_dump the variable it's value is NULL. 
Anyone know why?  Here's the function:

function auth_user($logged_in) {
  if (isset($logged_in)) {
list($s_username, $hash) = explode(',',$logged_in);
global $secret_word;
if (md5($s_username.$secret_word) == $hash) {
  $username = $s_username;
  return $username;
} else {
  die ("You have tampered with your session.");
}
  } else {
die ("Sorry, you are not logged in.  Please log in and try again.");
  }
}

Here's the code that calls the function which is in another script.

auth_user($_SESSION['login']);
var_dump($username);

Thanks,
Jason Giangrande


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



Re: [PHP] Returning values from functions

2003-07-09 Thread Jason Giangrande
Thanks.  I'm new to PHP, but still I should have seen that. :-)

Jason

On Wed, 2003-07-09 at 18:44, David Nicholson wrote:
> Hello,
> 
> 
> This is a reply to an e-mail that you wrote on Wed, 9 Jul 2003 at 23:40,
> lines prefixed by '>' were originally written by you.
> > auth_user($_SESSION['login']);
> > var_dump($username);
> 
> You are not collecting the value that your function returns. Try:
> $username = auth_user($_SESSION['login']);
> var_dump($username);
> 
> David.
> 
> -- 
> phpmachine :: The quick and easy to use service providing you with
> professionally developed PHP scripts :: http://www.phpmachine.com/
> 
>   Professional Web Development by David Nicholson
> http://www.djnicholson.com/
> 
> QuizSender.com - How well do your friends actually know you?
>  http://www.quizsender.com/
> (developed entirely in PHP)


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



[PHP] Writing to files

2003-07-11 Thread Jason Giangrande
Is there a way to write to a beginning of a file without it overwriting
data that's already there or do I have to write to the end of the file
in order to preserve data?  I ask because it would be much easier to
print the lines of the file out in order of last added first if I could
add lines at the top of the file.

Thanks,
Jason Giangrande


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



Re: [PHP] Writing to files

2003-07-11 Thread Jason Giangrande
Any ideas on how I can print the lines of my file in reverse order,
then?  Does fgets() always process from the beginning of the file even
if you open the file with the pointer at the end?  I tried to get the
line count of the file and go through each line of the file backwards
but that doesn't seem to work, so either it's impossible or I'm going
about it the wrong way.  Here's the code:

$fh = fopen("data.txt", "a+") or die("Could not open file");
$line_num = 0;
while (! feof($fh)) {
if ($line = fgets($fh, 1048576)) {
$line_num++;
}
}
while ($line_num != 0)) {
if ($line = fgets($fh, 1048576)) {
print $line;
$line_num--;
}
}

Thanks,
Jason


On Fri, 2003-07-11 at 15:04, David Nicholson wrote:
> Hello,
> 
> 
> This is a reply to an e-mail that you wrote on Fri, 11 Jul 2003 at 19:56,
> lines prefixed by '>' were originally written by you.
> > Is there a way to write to a beginning of a file without it
> > overwriting
> > data that's already there or do I have to write to the end of the file
> > in order to preserve data?  I ask because it would be much easier to
> > print the lines of the file out in order of last added first if I
> > could
> > add lines at the top of the file.
> 
> Not without reading the entire file into a variable first then appending
> that variable to the data you wish to add and saving the entire file again
> (which will obviously take longer than appending to the end of the file).
> 
> David.
> 
> -- 
> phpmachine :: The quick and easy to use service providing you with
> professionally developed PHP scripts :: http://www.phpmachine.com/
> 
>   Professional Web Development by David Nicholson
> http://www.djnicholson.com/
> 
> QuizSender.com - How well do your friends actually know you?
>  http://www.quizsender.com/
> (developed entirely in PHP)


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



Re: [PHP] Writing to files

2003-07-11 Thread Jason Giangrande
Thanks for the help guys.

Jason

On Fri, 2003-07-11 at 15:43, David Nicholson wrote:
> Hello,
> 
> 
> This is a reply to an e-mail that you wrote on Fri, 11 Jul 2003 at 20:37,
> lines prefixed by '>' were originally written by you.
> > Any ideas on how I can print the lines of my file in reverse order,
> > then?  
> 
> How about...
> 
> $fp = fopen("yourfile.txt","r");
> $filecontents = "";
> while(!feof($fp)){ 
> $filecontents.=fgets($fp,1024); // read entire file into
> $filecontents
> }
> 
> $filelines = split("\n",$filecontents); // split file into individual
> lines
> 
> for($i=(count($filelines)-1);$i>=0;$i--){ // loop through array in
> reverse order
> echo $filelines[$i] . "\n";
> }
> 
> -- 
> phpmachine :: The quick and easy to use service providing you with
> professionally developed PHP scripts :: http://www.phpmachine.com/
> 
>   Professional Web Development by David Nicholson
> http://www.djnicholson.com/
> 
> QuizSender.com - How well do your friends actually know you?
>  http://www.quizsender.com/
> (developed entirely in PHP)


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



[PHP] Couple of questions form a PHP newbie

2003-07-11 Thread Jason Giangrande
First question: I'm creating a custom content manager for a small site. 
It will basically be used to store short articles (several paragraphs
each).  Now my question is, is storing these to a text file going to
work or am I going to have problems later on when the file gets to be a
reasonable size.  I ask this, because the only way I can seem to work
with the text file is to read the entire file in and alter it that way. 
Are there any ways to edit or remove one line of a text file without
having to read the entire file first?  Would I be better off using a
database instead of a text file (keep in mind that I know nothing about
databases)?

Question two: I've read in several books that html checkbox forms can
pass multiple values to the server when more than one check box is
selected if they have the same name.  However, when I var_dump the
$_POST variable that should contain them I only get one value.  Anyone
have any ideas why?

Regards,
Jason Giangrande


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



Re: [PHP] Couple of questions form a PHP newbie

2003-07-11 Thread Jason Giangrande
Thanks for your help guys.  The checkboxes thing is working great.

Michael, regarding using files instead of a database, in your opinion,
eventually having a 10-20 MB text file isn't going to cause any server
problems if more than a few people are accessing the site at a time? 
I'm not talking millions, or even thousands of users, more like a few
hundred a day.  If using files should not be a problem, I would much
rather use that method in this particular project.

Thanks again,
Jason

On Fri, 2003-07-11 at 21:27, Michael Smith wrote:
> Jason Giangrande wrote:
> > First question: I'm creating a custom content manager for a small site. 
> > It will basically be used to store short articles (several paragraphs
> > each).  Now my question is, is storing these to a text file going to
> > work or am I going to have problems later on when the file gets to be a
> > reasonable size.  I ask this, because the only way I can seem to work
> > with the text file is to read the entire file in and alter it that way. 
> > Are there any ways to edit or remove one line of a text file without
> > having to read the entire file first?  Would I be better off using a
> > database instead of a text file (keep in mind that I know nothing about
> > databases)?
> > 
> 
> Flat files are perfectly fine. If you include them with PHP there is 
> almost no performance hit. However, you could use file() to put them in 
> an array and then array_search to figure out which key and only use that ...
> 
> > Question two: I've read in several books that html checkbox forms can
> > pass multiple values to the server when more than one check box is
> > selected if they have the same name.  However, when I var_dump the
> > $_POST variable that should contain them I only get one value.  Anyone
> > have any ideas why?
> 
> the name attribute for the checkboxes needs to be name="somevar[]" to be 
> put in an array.
> 
> > 
> 
> 
> > Regards,
> > Jason Giangrande
> > 
> 
> Cheers,
> -Michael
> 
> > 
> 


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



[PHP] Writing to file with function

2003-07-12 Thread Jason Giangrande
I have written this function to rewrite the contents of a text file
after it's been updated.  I store lines of data in an array and then
implode them into one string.  The problem is that I'm getting an extra
line break (in other words a blank line is showing up in my text file)
after I modify a particular line.  I checked the imploded string with
var_dump and don't see any line breaks besides the ones that separate
each line.  Anyone have any ideas as to why I'm getting an extra line
break?  The function is below with the code that calls it below that.

Jason

// Rewrite data file from array of file lines
function rewrite_file($lines) {
$filecontents = implode("\n", $lines);
$fh = fopen("data.txt", "w") or die("Could not open file.");
flock($fh, LOCK_EX);
if (fwrite($fh, $filecontents) == -1) {
die("File could not be written to.");
}
ftruncate($fh, ftell($fh)) or die("Error.");
flock($fh, LOCK_UN);
fclose($fh) or die("Error.");
}

<-###->

$uid = $_POST['id'];
$title = stripslashes(strip_tags(trim($_POST['title'])));
$name = array_search($username, $full_name);
$email = array_search($username, $user_email);
$date = $_POST['date'];
$category = $_POST['category'];
$article = stripslashes(trim($_POST['article']));

$data_array = array($uid, $title, $name, $email, $date, $category,
$article);
$data_line = implode($separator, $data_array)."\n";

$filelines = return_lines(); // Reads file and returns array of it's
lines.
for ($i = 0; $i <= count($filelines); $i++) {   // loop through array in
order
  if (strstr($filelines[$i], $uid) != FALSE) {
$data_pos = array_search($filelines[$i], $filelines);
array_splice($filelines, $data_pos, 1, $data_line);
  }
}
rewrite_file($filelines);


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



Re: [PHP] Writing to file with function

2003-07-12 Thread Jason Giangrande
Never mind everyone, I figured it out.  In this line:

$data_line = implode($separator, $data_array)."\n";

I was adding a newline when I didn't need too.

Jason

On Sat, 2003-07-12 at 17:03, Jason Giangrande wrote:
> I have written this function to rewrite the contents of a text file
> after it's been updated.  I store lines of data in an array and then
> implode them into one string.  The problem is that I'm getting an extra
> line break (in other words a blank line is showing up in my text file)
> after I modify a particular line.  I checked the imploded string with
> var_dump and don't see any line breaks besides the ones that separate
> each line.  Anyone have any ideas as to why I'm getting an extra line
> break?  The function is below with the code that calls it below that.
> 
> Jason
> 
> // Rewrite data file from array of file lines
> function rewrite_file($lines) {
>   $filecontents = implode("\n", $lines);
>   $fh = fopen("data.txt", "w") or die("Could not open file.");
>   flock($fh, LOCK_EX);
>   if (fwrite($fh, $filecontents) == -1) {
>   die("File could not be written to.");
>   }
>   ftruncate($fh, ftell($fh)) or die("Error.");
>   flock($fh, LOCK_UN);
>   fclose($fh) or die("Error.");
> }
> 
> <-###->
> 
> $uid = $_POST['id'];
> $title = stripslashes(strip_tags(trim($_POST['title'])));
> $name = array_search($username, $full_name);
> $email = array_search($username, $user_email);
> $date = $_POST['date'];
> $category = $_POST['category'];
> $article = stripslashes(trim($_POST['article']));
> 
> $data_array = array($uid, $title, $name, $email, $date, $category,
> $article);
> $data_line = implode($separator, $data_array)."\n";
> 
> $filelines = return_lines(); // Reads file and returns array of it's
> lines.
> for ($i = 0; $i <= count($filelines); $i++) { // loop through array in
> order
>   if (strstr($filelines[$i], $uid) != FALSE) {
> $data_pos = array_search($filelines[$i], $filelines);
> array_splice($filelines, $data_pos, 1, $data_line);
>   }
> }
> rewrite_file($filelines);
> 


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



[PHP] Replacing newlines (\n) with smething else

2003-07-13 Thread Jason Giangrande
Hi,

I'm trying to replace newlines with something else.  For this example
I'll use  as the thing to replace a newline with.  This is what I
tried and it doesn't work.

$article = str_replace("\n", "", $article);

What am I doing wrong?  $article is the string to replace the newlines
in.  I tried this with a period and that works as expected.  Can I not
replace newlines this way?

Thanks,
Jason Giangrande




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



Re: [PHP] Re: Replacing newlines (\n) with smething else

2003-07-13 Thread Jason Giangrande
I did not know about nl2br.  Thanks.

But what if say I want to replace a newline with something else, say
.  How would I do that?

Jason


On Sun, 2003-07-13 at 17:09, J. Cox wrote:
> "Jason Giangrande" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Hi,
> >
> > I'm trying to replace newlines with something else.  For this example
> > I'll use  as the thing to replace a newline with.  This is what I
> > tried and it doesn't work.
> >
> > $article = str_replace("\n", "", $article);
> >
> > What am I doing wrong?  $article is the string to replace the newlines
> > in.  I tried this with a period and that works as expected.  Can I not
> > replace newlines this way?
> 
> why not just:
> 
> $article = nl2br($article);
> 
> --
> J. Cox
> http://www.xaraya.com
> 
> 
> 


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



Re: [PHP] Replacing newlines (\n) with smething else

2003-07-13 Thread Jason Giangrande
Perhaps.  When getting text from a form field, what is substituted for a
newline (i.e. when someone hits enter).

Jason

On Sun, 2003-07-13 at 17:21, David Otton wrote:
> On 13 Jul 2003 17:01:24 -0400, you wrote:
> 
> >I'm trying to replace newlines with something else.  For this example
> >I'll use  as the thing to replace a newline with.  This is what I
> >tried and it doesn't work.
> 
> nl2br() in the specific case
> 
> >$article = str_replace("\n", "", $article);
> >
> >What am I doing wrong?  $article is the string to replace the newlines
> >in.  I tried this with a period and that works as expected.  Can I not
> >replace newlines this way?
> 
> But in the general case, your code looks ok to me.
> 
> echo (str_replace("\n", "", "foo\nbar"));
> 
> returns "foobar" here. Maybe $article doesn't contain what you think it
> does?
> 
> (BTW, I prefer to replace "\n" with "\n", but that's just a style
> thing.)
> 


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



Re: [PHP] Replacing newlines (\n) with smething else

2003-07-13 Thread Jason Giangrande
It's really strange because I type the following into the form field.

Test
Test

Test

And get this as output.
Test Test Test

Do form fields not preserve spacing or line breaks?

Jason


On Sun, 2003-07-13 at 17:45, David Otton wrote:
> On 13 Jul 2003 17:27:04 -0400, you wrote:
> 
> >Perhaps.  When getting text from a form field, what is substituted for a
> >newline (i.e. when someone hits enter).
> 
> You can work it out for yourself. Run over the string, displaying each
> character as it's ASCII equivalent with ord(). Eg
> 
>   for ($i = 0; $i < strlen($article); $i++) {
>   echo ("'" . $article[$i] . "'=" . ord($article[$i]) . ', ');
>   }
> 
> (My guess is that you're seeing the difference between a wrapped line and
> the user explicitly hitting enter)
> 


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



Re: [PHP] Replacing newlines (n) with smething else

2003-07-13 Thread Jason Giangrande
My problem is solved.  Thank you to everyone who responded.

Jason

On Sun, 2003-07-13 at 18:33, David Nicholson wrote:
> Hello,
> 
> 
> This is a reply to an e-mail that you wrote on Sun, 13 Jul 2003 at 23:12,
> lines prefixed by '>' were originally written by you.
> 
> Maybe the browser you are using to fill in the form field is using a
> different type of line break. Although I have never seen it done, r by
> itself can be used to cause a line break and if that is being done your
> code will not be detecting it.
> 
> David
> 
> -- 
> phpmachine :: The quick and easy to use service providing you with
> professionally developed PHP scripts :: http://www.phpmachine.com/
> 
>   Professional Web Development by David Nicholson
> http://www.djnicholson.com/
> 
> QuizSender.com - How well do your friends actually know you?
>  http://www.quizsender.com/
> (developed entirely in PHP)


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



[PHP] Forms and PHP

2003-07-19 Thread Jason Giangrande
I have a question about forms and PHP.  Here's what I'm looking to do. 
I'm trying to set up a spell checker that checks text entered in a form,
but I want the check results to show up in a different window so that
the user can change the misspelled words if they'd like.  In other
words, I want to be able to click a link and have another page open that
checks the spelling.  My question is how can I send the text from the
form to this other page (which, right now, is a separate php script) so
it can be spell checked without actually submitting the actual form
first?  In other words, I would like the user to be able to check the
spelling without actually submitting the form.

Thanks,
Jason Giangrande


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



Re: [PHP] Forms and PHP

2003-07-19 Thread Jason Giangrande
Thanks guys.  I think I'll try it first as Chris suggested and see how
that goes.  Thanks again.

Jason

On Sun, 2003-07-20 at 00:55, Justin French wrote:
> This is done with javascript... without getting too off topic... JS can 
> get the contents of the textarea, and submit it via get (maybe post as 
> well) to another (pop-up) window.  the pop-up window can highlght 
> misspelled words, and even make dynamic changes to the content in the 
> first window.
> 
> it's pretty complex stuff though... and definitely NOT for the JS 
> newbie...
> 
> look around the JS lists and sites for something that might give you a 
> head start.
> 
> 
> justin
> 
> 
> 
> On Sunday, July 20, 2003, at 02:37  PM, Jason Giangrande wrote:
> 
> > I have a question about forms and PHP.  Here's what I'm looking to do.
> > I'm trying to set up a spell checker that checks text entered in a 
> > form,
> > but I want the check results to show up in a different window so that
> > the user can change the misspelled words if they'd like.  In other
> > words, I want to be able to click a link and have another page open 
> > that
> > checks the spelling.  My question is how can I send the text from the
> > form to this other page (which, right now, is a separate php script) so
> > it can be spell checked without actually submitting the actual form
> > first?  In other words, I would like the user to be able to check the
> > spelling without actually submitting the form.
> >
> > Thanks,
> > Jason Giangrande
> >
> >
> > -- 
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> > ---
> > [This E-mail scanned for viruses]
> >
> >
> 


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



[PHP] Deleting array fields...

2003-07-22 Thread Jason Giangrande
Is there a way to delete array fields without resort the keys?  The keys
of this particular array are the position of the words it holds to their
position in a string and if they are changed it screws everything up.  I
tried using array_splice but that, unfortunately, rearranges the keys. 
So, to reiterate, what I want to do is remove a key from an array but
not have the keys automatically reassigned.

Thanks,
Jason Giangrande


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



Re: [PHP] Deleting array fields...

2003-07-22 Thread Jason Giangrande
Thanks Curt.

Your suggestion works great.  I had come up with this to clear the
array, which also worked for me in this instance, by doing this

$array['item'] = "";

But I think your suggestion is better because one I have used the array
fields once I have no further use for them so I might as well get rid of
them.  Thanks again.

Jason

On Tue, 2003-07-22 at 22:36, Curt Zirzow wrote:
> * Thus wrote Jason Giangrande ([EMAIL PROTECTED]):
> > Is there a way to delete array fields without resort the keys?  The keys
> > of this particular array are the position of the words it holds to their
> > position in a string and if they are changed it screws everything up.  I
> > tried using array_splice but that, unfortunately, rearranges the keys. 
> > So, to reiterate, what I want to do is remove a key from an array but
> > not have the keys automatically reassigned.
> > 
> > Thanks,
> > Jason Giangrande
> 
> unset($array['item']);
> 
> I don't think it rearranges it. perhaps the docs should mention this in
> the array section. I only remember unset because of a big discussion
> about its behavior a while back.
> 
> HTH,
> 
> Curt
> -- 
> "I used to think I was indecisive, but now I'm not so sure."


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



[PHP] Global variable question question

2003-07-23 Thread Jason Giangrande
When registered globals is set to off this does not effect the $PHP_SELF
variable right?  In other words I should be able to call $PHP_SELF with
out having to do this $_SERVER['PHP_SELF'], right?

Thanks,
Jason Giangrande


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



Re: [PHP] Global variable question question

2003-07-23 Thread Jason Giangrande
Actually, I am running PHP 4.3.2 on a Gentoo Linux box with
registered_globals set to Off and $PHP_SELF does work.  The production
box running Red Hat and PHP 4.3.0, with register_globals also set to
Off, doesn't work using $PHP_SELF (as apparently it should), and this is
why I was asking.

Jason

 On Wed, 2003-07-23 at 16:13, Lars Torben Wilson wrote:
> On Wed, 2003-07-23 at 12:19, Jason Giangrande wrote:
> > When registered globals is set to off this does not effect the $PHP_SELF
> > variable right?  In other words I should be able to call $PHP_SELF with
> > out having to do this $_SERVER['PHP_SELF'], right?
> > 
> > Thanks,
> > Jason Giangrande
> 
> Without going into why you didn't read the manual or just try it, the
> answer is 'wrong'. ;) If register_globals is off, $_SERVER['PHP_SELF']
> is what you will need.
> 
> 
> Good luck,
> 
> Torben
> 


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



Re: [PHP] Include Problems

2003-07-24 Thread Jason Giangrande
Is the code you are trying to call $subnav from inside a function?  If
so you will need to tell the function that by using the global keyword
(i.e. global $subnav;).  Other than that the code you've shown looks
right to me.

Jason

On Thu, 2003-07-24 at 13:55, Eric Fleming wrote:
> I am having some problems using variables in included files.  Can someone
> please look at my code below and see how I might accomplish what I am trying
> to do?
> 
>   $subnav = "home";
>  include("incHeader.php");
> ?>
> 
> 
> 
> The content would go here.
> 
> 
> 
> 
> 
> Now, when I try to reference the subnav variable in the inHeader.php or
> incFooter.php files, it comes up blank.  I am basically trying to adjust the
> navigation on each page depending on the page I am on.  I am just learning
> PHP, have programmed in ColdFusion for years and in ColdFusion this was not
> a problem.  Any ideas?
> 
> Eric Fleming
> 
> 


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



Re: [PHP] Include Problems

2003-07-24 Thread Jason Giangrande
Eric, If you want to check to see if $subnav is equal to "home" you want
to use == and not =.  Perhaps this is your problem.

Jason

On Thu, 2003-07-24 at 15:35, Eric Fleming wrote:
> Here is a snippet from the header file.  You can see that I am just trying
> to determine what the value of the subnav variable is set to in order to
> determine which navigational link is bold.  There are other places the
> variable is used, but you can get an idea based on what is below.  Thanks
> for any help.
> 
> <-incHeader.php-->
> 
> 
> 
> [Site Name]
> 
> 
> 
> 
> 
>  href="index.php">home
> 
> 
> 
> 
> <-incHeader.php-->



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



Re: [PHP] Include Problems

2003-07-24 Thread Jason Giangrande
Eric, I tried your code on my machine and it seems to print the name of
the variable just fine.  The only change I had to make to your code was
add the long PHP tags (i.e. 


[Site Name]







home






It printed home twice once bolded and as a link.  I don't think the
problem is your code maybe some weird php.ini setting is set, as to
which one however I couldn't say.

Jason

On Thu, 2003-07-24 at 15:44, Eric Fleming wrote:
> Yeah, that is a problem, but I can't even print out the value of the subnav
> variable.  It prints nothing when I try to print the variable.
> 
> 
> "Jason Giangrande" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Eric, If you want to check to see if $subnav is equal to "home" you want
> > to use == and not =.  Perhaps this is your problem.
> >
> > Jason
> >
> > On Thu, 2003-07-24 at 15:35, Eric Fleming wrote:
> > > Here is a snippet from the header file.  You can see that I am just
> trying
> > > to determine what the value of the subnav variable is set to in order to
> > > determine which navigational link is bold.  There are other places the
> > > variable is used, but you can get an idea based on what is below.
> Thanks
> > > for any help.
> > >
> > > <-incHeader.php-->
> > >
> > > 
> > > 
> > > [Site Name]
> > > 
> > > 
> > > 
> > > 
> > > 
> > >  > > href="index.php">home
> > > 
> > > 
> > > 
> > >
> > > <-incHeader.php-->
> >
> >
> 
> 


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



[PHP] Checking if a host is online

2003-11-29 Thread Jason Giangrande
I'm creating an application for an Intranet that, among other things, is
supposed to check to see if particular hosts are online, and if so, what
their IP address is.  Anyone know how I can accomplish this?  I tried
using exec("host $host"); (where $host is the hostname) and while this
gets the IP it gets the IP address sometimes even if the host is not
active, because a DNS record for the system still exists.  I also looked
into the gethostbyname() function, but that has similar problems to
using the external host command.  I also tried to use an external ping
command (ping -c 1 $host), and while I could get that to work, since it
returns non-zero status if the host can not be contacted, it takes quite
a while to execute for even a few hosts at once.  

Anyone ever do this king=d of thing before or have any suggestions on
what might work?
-- 
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com


signature.asc
Description: This is a digitally signed message part


Re: [PHP] Checking if a host is online

2003-11-29 Thread Jason Giangrande
On Sat, 2003-11-29 at 12:20, Adam Maas wrote:
> why not try:
> 
>   passthru("ping $host");
> 
> Adam

That still takes a little while to execute on multiple hosts,  Plus I
need to modify the output of the command to print just the IP address
and discard the rest of the output.
-- 
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com


signature.asc
Description: This is a digitally signed message part


Re: [PHP] Checking if a host is online

2003-11-29 Thread Jason Giangrande
On Sat, 2003-11-29 at 12:32, David T-G wrote:
> 3) At the very least, cut your ping timeout down to the smallest
> acceptable; in general, a full second is plenty of time to get nearly
> anywhere on your continent (ain't it great? :-) and so your intranet
> should be more than happy with that allowance.
> 
> HTH & HAND
> 
> :-D

Thanks for your help guys.  Cutting the ping timeout helped speed things
up quite a bit.  I will also look into BigBrother and your other
suggestions.  Thanks again.
-- 
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com


signature.asc
Description: This is a digitally signed message part


[PHP] Showing all users who are logged in

2004-07-27 Thread Jason Giangrande
Anyone have any suggestions as to the best way to keep track of all 
users who are logged in at a given time?  I thought of writing them to a 
temp text file and them deleting the names from the file when a user 
logged out, but I think there has to be a better way.  Anyone have any 
suggestions?

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Showing all users who are logged in

2004-07-28 Thread Jason Giangrande
Vail, Warren wrote:
I did one application where I used the PHP session table to tell who was
logged on, and which area of the application they were most recently in.
One of several flaws, was that I used Kill session to logoff, and that
caused them to disappear from any count of users logged on.  Course, if they
had logged off, then they weren't logged on, but on the other side, users
were counted for every session they created, and closing and opening new
browser sessions caused them to be counted multiple times, and continue to
be counted until session "garbage cleanup" removed their session entries,
unless I used the session timestamp in my count algorithm.  Session was
nice, because if a user was causing a problem, I could kill his session
entry, effectively logging him off, forcing him to logon again.
Warren Vail
Thanks guys.  Between your suggestions, I managed to come up with a 
solution.

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] converting from name - id and PHP not seeing it?

2004-09-23 Thread Jason Giangrande
[EMAIL PROTECTED] wrote:
I jsut finished converting my pages to be W3C compliant...
One of the recuring 'errors' I had was my form elements were all using the 
'name' atrtribute...
apparently, this is bad, and I was suggested to switch them ti use the 
'id' attribute...

all good, I did that, but for some reason, when I post that info to 
another page, it's not carried over...
name works fine, id does not...

Am I being a tool?
What am I supposed to use...?
I use $_POST[variable] in my code..., so I tried just $variable... that 
failed too...?

Thoughts?
Tris...
The name attribute on forms is not usually needed, and I have used the 
id attribute before and they work fine.  Do you have names on each 
input, select, or any of the other form elements you may have?  Use 
these to extract the form information, and it should work just fine.

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] require_once '../config.php'; doesn't work?

2004-04-09 Thread Jason Giangrande
Mike Zornek wrote:
Is it true I can't include a file up a dir like this:

require_once '../config.php';
You should be able to include a file up one (or more) directories.  Are 
you sure it's only up one directory from were your script is being 
called from?

This seems to work though:

require_once 'settings/db.php';

Strange.
--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] MySQL query

2004-01-27 Thread Jason Giangrande
I have the following query.

UPDATE link SET hits = hits+1 WHERE website_link = '$link'

$link is the website link that was clicked on.

The query works fine.  The problem is if $link is a website that does
not exist in the database mysql_query(); still returns true even though
nothing was updated.  Why is this, and anyone have any suggestions on
the easiest way to check to see if $link exists in the database before
updating it?

Here's the code. db_error() is a function that calls mysql_error() and a
few other things.

$link = $_GET['link'];
$query = "UPDATE link SET hits = hits+1 WHERE website_link = '$link'";
$result = @ mysql_query($query, $connection) or db_error();
var_dump($result);  // True even if $link does not exist in database.
header("Location: $link");
die();

** db_error() function **
function db_error() {   // Dies with fatal error
global $db_name;
if (mysql_error()) {
die("Error " . mysql_errno() . ": " . mysql_error());
} else {
    die("Could not connect to database, $db_name");
}
}
-- 
Jason Giangrande <[EMAIL PROTECTED]>


signature.asc
Description: This is a digitally signed message part


Re: [PHP] Small Problem - could you help me, please?

2004-03-17 Thread Jason Giangrande
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Labunski wrote:
| $ip = getenv ("REMOTE_ADDR");
|
| function kick() {
| $file_ip = file("log.txt");
| foreach($file_ip as $value_ip ) {
| $kick .= "$value_ip";
| }
| return $kick;
| }
| if ($ip == kick()){
| echo "Sorry, the access is denied.";
|
| exit;
| }
In the function you seem to be appending all the ip addresses in the
file to $kick.  When you return kick it will hold all of the ips and not
just and will therefore not be equal to $ip.
You might want to try something like this:

$ip = getenv ("REMOTE_ADDR");

function kick($ip) {
~$file_ip = file("log.txt") or die("Can't open file");
~foreach ($file_ip as $value_ip) {
$value_ip = preg_replace("/\n/", "", $value_ip);
~if ($ip == $value_ip) {
return true;
}
~}
~return false;
}
if (kick($ip)) {
echo "Sorry, the access is denied.";
}
It seems each ip address in the $file_ip has a new line on the end too,
so you need to remove that before the current ip address in $ip will
match anything that is in the file.
Hope this helps.

- --
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFAWN6GjfevYzbk95IRAvx3AJ9jVbiSI0gyf50AkeJD63Z8LHT0ggCfQEqE
RGunvEgTHkKJylmnywLxseM=
=LJd1
-END PGP SIGNATURE-
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] HTML/PHP page print

2004-03-18 Thread Jason Giangrande
Manisha Sathe wrote:
How can avoid other stuff on my web page ?
I assume you want to only print the information and not the page header, 
footer, navigation, etc.  There are several ways to do this.  The best 
way is with CSS.  However, if you have not created your page primarily 
with CSS this won't work real well.  The second step is to simply remove 
 any headers or footers that you are including in your page when you 
want to print.  In others words create a link on the page that says 
print that when clicked will not load any footers or headers.  If you 
don't include any footers or headers, you could create a script that 
would remove  tags and some others in order to print only the 
relevant material.

Also when i print then title of document / page no / url / date also get displayed.
How can i avoid it ?
This kind of information is usually from the OS, browser or printer 
driver.  Therefore, it would be very hard if not impossible to turn off 
through server-side scripting or even with JavaScript.

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: string function that inserts a char

2004-03-20 Thread Jason Giangrande
Five wrote:
"Five" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]

I just finished looking through string functions
http://us2.php.net/manual/en/ref.strings.php
and can't find one that inserts a character, not replaces one.
If there's a string that's over 50 chars long without a space, I want to insert a 
space without replacing or losing any of the
original characters. Is there a function to do that?
advance thanks,
Dale


I should add that, unless there's a function that does it all, I'm not really 
concerned with the finding the 50th char part. I know
there's other funcs for that kind of thing. It's just that all I'm trying to do is 
make sure that when the string is output, it will
wrap to the width of a table and not stretch the table width to suit it's fancy.
If I manufacture a function to do all of the little things necessary to make this 
thing wrap, it seems like a lot of ugly code to do
a simple task.
Use substr_replace() and set the length value to 0.  Here's an example:

$text = "Thistext";
echo "$text";
$text = substr_replace($text, " ", 4, 0);
echo $text;
Test it and you will see that a space is added into the text without 
replacing any of it.

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Methods for creating HTML with PHP

2004-03-24 Thread Jason Giangrande
I'm looking for an easy way to write all my HTML using PHP.  I could do 
this with a bunch of print statements or the like, but that doesn't seem 
like a real good solution.  I noticed that PEAR has several packages for 
creating HTML.  Has anyone used any of these packages?  I'm particularly 
interested in the HTML_Common, HTML_Page, and HTML_CSS packages.  The 
HTML_Page package, which to me seems like the one package that actually 
outputs HTML, is marked as "beta".  Anyone know if there are any 
alternative packages that do a similar thing?

Also, is it possible to download a package marked beta with PEAR, or 
does it need to be downloaded manually?

Thanks,
--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Methods for creating HTML with PHP

2004-03-24 Thread Jason Giangrande
Raditha Dissanayake wrote:
How about just escaping out of php :-) and embedding the html direct?

Jason Giangrande wrote:

I'm looking for an easy way to write all my HTML using PHP.  I could 
do this with a bunch of print statements or the like, but that doesn't 
seem like a real good solution.  I noticed that PEAR has several 
packages for creating HTML.  Has anyone used any of these packages?  
I'm particularly interested in the HTML_Common, HTML_Page, and 
HTML_CSS packages.  The HTML_Page package, which to me seems like the 
one package that actually outputs HTML, is marked as "beta".  Anyone 
know if there are any alternative packages that do a similar thing?

Also, is it possible to download a package marked beta with PEAR, or 
does it need to be downloaded manually?

Thanks,
That's the thing.  I'm looking for an alternative way of writing HTML 
into PHP pages.  I did a few simple pages a while ago just using print 
statements instead of closing the PHP tag and then writing HTML.  It 
made the code a little easier to follow.  The problem is that print 
statements can add up fast, so using to many of them in one page is 
probably just as hard to follow as closing a PHP block, so you can write 
some HTML.  That was why I was looking for an alternative way to write 
HTML in PHP pages.

I tried the HTML_Page class from PEAR, but it seems to have some issues 
still.  I guess that's why it's still in beta.  I've decided I'll try 
and write something on my own for now that incorporates a few things 
I've seen in other classes (mainly HTML_Common, and HTML_Page).

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Header Redirect & POST

2004-03-25 Thread Jason Giangrande
Chris Thomas wrote:
I am not sure if this was designed like this, or if its just something im
doing wrong.
Im posting some data to a processing page, where i handle it then use
Header('Location: other.php') to direct me to another page.
The problem that im running into is that the posted data is available in
other.php.
I would like to get it so that in other.php $_POST  should be an empty array
Any suggestions??

Chris

If the processing page and other.php page are two separate pages I don't 
see how you could be getting the same $_POST data that the processing 
page is receiving.  You aren't passing any data from your processing 
page to hidden form inputs (or something) on that page before you call 
header() are you?  Perhaps if you gave an example of your code I might 
have a better idea of what is going on.  You could also try using 
unset($_POST) in other.php to make sure $_POST is empty for that page.

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: Methods for creating HTML with PHP

2004-03-25 Thread Jason Giangrande
Justin French wrote:
On Friday, March 26, 2004, at 04:47  AM, Resell Domain Names wrote:

Why not use Smarty or another template engine? (http://smarty.php.net/)


Smarty has a lot of overhead.  PHP is a perfectly good templating engine 
all by itself.

What the OP may or may not have understood is that PHP and HTML can be 
mixed together:
I do understand that PHP and HTML can be mixed together.  That's how 
I've been coding with it for the last nine months.  My question was is 
there a viable solution to mixing PHP and HTML code.  I think mixing PHP 
and HTML code can get a little confusing.  I can understand it when I 
write it, but a few months down the road it will take me a little while 
to figure out what the script is doing since I need to mentally separate 
the HTML code from the PHP code.

As I stated in past posts I have yet to find a decent solution for 
handle the building of an HTML page with PHP.  I tried HTML_Page from 
PEAR, but it still needs some work before it is fully usable.  I also 
contemplated writing my own HTML class, but so far the only workable 
solution I have come up with is pretty much what HTML_Page already does.

---







---
As for Smarty, well, anything it can do, PHP can do better and faster, 
without the overhead :)
Personally I've used Smarty only a little.  It has it purposes in some 
situations, but since I know PHP (somewhat anyway :-D) I wouldn't need 
it for most projects.

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] What's the use in OOP?

2004-03-29 Thread Jason Giangrande
Stephen Craton wrote:
I've been reading up on object oriented programming in PHP for a while now
and I just don't get what's the use in using it. It supposedly makes it
faster, but I don't really see how in any of my scripts. What's the
advantage of OOP anyway, and why are so many people using it now? What does
it have to offer then just creating files full of functions to include later
like I've always done?
It's really good for code organization and reuse.  The ability to reuse 
code every easily is it's best feature, IMO.

Also, Rob has good points, too.

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Apache version... 1.3.29 vs 2.0.

2004-04-02 Thread Jason Giangrande
Frano ILICIC wrote:
Hello,

I just wonder what is the best apache version to run PHP 4.35?
Just wondering if there is an obvious choice? 
I'm running both 1.3.x and 2.0.x (both currently running PHP 4.3.4) and 
both seem to work equally well.  I would say that if the your server is 
running Linux  and you don't need any of the new fancy modules that can 
be used with Apache 2.0.x use 1.3.x.  If your server is running Windows 
you will probably want to run Apache 2.0.x since that is supposed to run 
much better under Windows than 1.3.x.

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Question, what to do when finding an error while validating data

2004-04-05 Thread Jason Giangrande
Mike Zornek wrote:

Oops, forgot to send my original response to the list last time.

On 4/5/04 1:33 PM, "Jason Giangrande" <[EMAIL PROTECTED]> wrote:
What I usually do is create a select box that has only the values of the
enum.  That way no one should be able to (in theory) put any value other
than the ones you set.  You could also code up a check that runs before
you build your sql query. Simply check that if the value of the input of
that enum field is anything other than what you expect, change it to
your default then inset it into your database.


I am going to create a select box, but am still trying to write enough tests
to catch myself if I try to do something foolish. The "in theory" part is
what I'm trying to check for. :-)
I questions is, if someone tries to set the var to an invalid type should I
throw a warning, or die or do nothing and just use the default or previous
value. I'm inclined to stay away from the last option cause it invites
strangeness to people who might be new to the system.
As long as register_globals is set to off what come in from your select 
box should be used as the value of the enum field.  It is always best to 
do as much data validation as you feel is worth it.  IMO, in the case of 
using a select box to set the values of an enum MYSQL field, (unless 
this application is for something that is really security conscience, 
like banking or something), I feel I can usually trust the select field. 
 Remember that if someone tries to set the enum filed to something 
other than what is specified, an empty string will be stored. 
Therefore, when you are reading from the database you could always check 
for that, too.

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Hiding email address from Robots ??

2004-04-08 Thread Jason Giangrande
news wrote:
Looking for opinions before I start using this to hide the email address on
a page
$nx = "username";
$sx = "domain";
$mx = "[EMAIL PROTECTED]";
Then mailto:

Hopefully a Robot would read the address as the result of $mx, which is
totally useless - but it seems too easy.
Perhaps I'm missing something (and if I am, please let me know), but how 
would [EMAIL PROTECTED] be totally useless to email harvesting robots?  If 
$nx was 'user' and $sx was 'example.com'.  The mailto would be displayed 
as 'mailto:[EMAIL PROTECTED]' which any mail robot will clearly be able 
to use.  Any robots will not read the page until all PHP code has run 
and returned the page as complete html.

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Serializing objects and storing them is sessions

2004-04-08 Thread Jason Giangrande
I'm having a problem unserializing objects that are passed from page to 
page with sessions.  Registered globals is disabled so I am using the 
$_SESSION array to store session variable and am not using 
session_register().  Here's what I'm doing.

On first page:

$auth = new Class();
session_start();
$_SESSION['auth'] = serialize($auth);
Second page:

session_start();
var_dump($_SESSION);
$auth = unserialize($_SESSION['auth']);
var_dump($auth);
When I var_dump() $_SESSION it appears to be a string representation of 
the object.  However, when I try to unserialize() it and store it in 
$auth the value is bool(false) and not an object.

Can anyone tell me what I am doing wrong?

Thanks,
--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Serializing objects and storing them is sessions

2004-04-08 Thread Jason Giangrande
Jason Wong wrote:
What does the php error have to say about it?
php error?  I'm sorry but I don't know what you are talking about.  The 
only error I get is that a call to a member function on a non-object. 
Here's the error (path has been changed):

Fatal error: Call to a member function on a non-object in 
/path/to/php/script/test.php on line 16

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Serializing objects and storing them is sessions

2004-04-08 Thread Jason Giangrande
Jason Wong wrote:
On Friday 09 April 2004 11:07, Jason Giangrande wrote:

Jason Wong wrote:

What does the php error have to say about it?
php error?  I'm sorry but I don't know what you are talking about. 


Sorry, I meant to say "php error log". You should ALWAYS enable full error 
reporting. And whenever you encounter a problem the first thing you should do 
is check the error log.
I do not have error logging enabled.  All errors are displayed to the 
screen.  This is not a production server I am testing on.

The
only error I get is that a call to a member function on a non-object.
Here's the error (path has been changed):
Fatal error: Call to a member function on a non-object in
/path/to/php/script/test.php on line 16


And what code are you running to get that error? Because AFAICS the code you 
presented cannot produce that error.
I wasn't showing the method call, because it isn't what's causing the 
problem (well I don't think so, anyway).  The problem is the session not 
unserializing for some reason.  Here is the code.

Page one:

require_once('UserAuth.inc');

$auth = new UserAuth('file', array('file' => '/tmp/password'));

if (!empty($_POST['username']) && !empty($_POST['password'])) {
//$auth = new UserAuth('file', array('file' => '/tmp/password'));
if ($login = $auth->login($_POST['username'], $_POST['password'], 
$secret_word)) {
		session_start();
		$_SESSION['auth'] = serialize($auth);
		//session_register("auth");
		//var_dump($_SESSION['auth']);
		header('Location: http://example/code/php/test.php');
		//$auth->debug();
	die();
	} else {
		var_dump($login);
		echo 'Test failed!';
		die();
	}
}



Page two:

require_once('UserAuth.inc');

session_start();

if (!empty($_SESSION['auth'])) {
var_dump($_SESSION['auth']);
$userauth = unserialize($_SESSION['auth']);
//$auth = $_SESSION['auth'];
var_dump($userauth);
}
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">


UserAuth Test





Logout



--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Serializing objects and storing them is sessions

2004-04-08 Thread Jason Giangrande
electroteque wrote:
May i ask what the advantage of storing objects in session is ? Does it
cause overhead ? Like should i store the most common classes like the db and
auth class in a session ?
The advantage of storing an object is to keep it's properties.  This way 
you can use values that have already been stored in the class on future 
pages.  Therefore, I doubt there would be much advantage to store 'db' 
or 'auth' in a session, but I guess it really all depends on what you 
are doing.  Currently, I am just trying to see if I can make sure a 
class I am writing will work when storing objects in sessions, but thus 
far I am unable to unserialize the sessions.

To be honest, I guess it really isn't that different than storing them 
in a file, since they technically are stored in a file.  Supposedly you 
don't have to manually serialize or unserialize them if you set the 
initial session variable with session_register(), so that might be a 
plus.  Unfortunately I have been unable to get that to work.  Actually, 
I have been unable to get a session to unserialize manually either.

I do not know if storing an object in a session causes anymore overhead 
than storing them in a file or database.  If I was to guess, storing 
them in a database might be less taxing.

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Serializing objects and storing them is sessions [fixed]

2004-04-08 Thread Jason Giangrande
Jason Giangrande wrote:
I'm having a problem unserializing objects that are passed from page to 
page with sessions.  Registered globals is disabled so I am using the 
$_SESSION array to store session variable and am not using 
session_register().  Here's what I'm doing.

On first page:

$auth = new Class();
session_start();
$_SESSION['auth'] = serialize($auth);
Second page:

session_start();
var_dump($_SESSION);
$auth = unserialize($_SESSION['auth']);
var_dump($auth);
When I var_dump() $_SESSION it appears to be a string representation of 
the object.  However, when I try to unserialize() it and store it in 
$auth the value is bool(false) and not an object.

Can anyone tell me what I am doing wrong?
Don't I feel stupid now.  I have solved my problem.  I had written a 
__sleep() function that I had forgotten about, and as it turns out, it 
was breaking things.  Not really sure why.  It was just creating the 
array of object properties to be serialized.  Commenting it out fixes 
the problem I was having.

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Serializing objects and storing them is sessions [fixed]

2004-04-09 Thread Jason Giangrande
Kelly Hallman wrote:
Apr 9 at 1:44am, Jason Giangrande wrote:

Jason Giangrande wrote:

I'm having a problem unserializing objects that are passed from page to 
page with sessions.  Registered globals is disabled so I am using the 
$_SESSION array to store session variable

When I var_dump() $_SESSION it appears to be a string representation of 
the object.  However, when I try to unserialize() it and store it in 
$auth the value is bool(false) and not an object.

Can anyone tell me what I am doing wrong?
Don't I feel stupid now.  I have solved my problem.  I had written a
__sleep() function that I had forgotten about, and as it turns out, it
was breaking things.  Not really sure why.  It was just creating the
array of object properties to be serialized.  Commenting it out fixes
the problem I was having.


You shouldn't serialize() objects prior to assign to a session variable.  
The default session handler automatically serializes the data. Assigning a
serialized object value to a session just adds redundancy and overhead. 
Actually, only if you create the session with session_register() are 
they serialized automatically.  If you simply assign an object to the 
$_SESSION array it must be serialized manually.

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Serializing objects and storing them is sessions [fixed]

2004-04-09 Thread Jason Giangrande
Kelly Hallman wrote:
Apr 9 at 11:12am, Jason Giangrande wrote:

You shouldn't serialize() objects prior to assign to a session variable.  
The default session handler automatically serializes the data. Assigning a
serialized object value to a session just adds redundancy and overhead. 
Actually, only if you create the session with session_register() are 
they serialized automatically.  If you simply assign an object to the 
$_SESSION array it must be serialized manually.


When writing the above response, I had noted the documentation mentioned
something to this effect. I believe this is incorrect or ambiguous.
Try it without serializing, it works.
After retesting, it seems you are correct.  I guess the same bad 
__sleep() code that was causing the object not to unserialize at all was 
also preventing automatic serialization.  However; it does not seem to 
harm anything if serialize() and unserialize() are called manually on an 
object.  It's just extra code that doesn't do anything, and therefore, 
can be removed.

--
Jason Giangrande <[EMAIL PROTECTED]>
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php