RE: [PHP] advise on simplfying session usage

2012-01-12 Thread mail.pmpa
When I have many calls to $_SESSION I do:

$s = &$_SESSION;
$s['foo'] = 'bar';

echo $s['foo'];  //bar

-Original Message-
From: Haluk Karamete [mailto:halukkaram...@gmail.com] 
Sent: sexta-feira, 13 de Janeiro de 2012 01:17
To: php-general@lists.php.net
Subject: [PHP] advise on simplfying session usage

Again, coming from ASP background, I'm trying to minimize the typing for
most needed functionalities..

in asp, to set a session var, you go <%session("age")=90%> and to output it,
you just go <%=session("age")%>

in php, you've got to _SESSION['age']=90. that's a lot of keyboarding, lots
of double key strokes and the entire word session has to be uppercase.
of course, if you use an IDE and you get fast at it, this may not be an
issue but I wanted to simplify it anyway.

so the plan is this



To achieve this; I wrote this preliminary function;

function _s($var,$val = "r4r53d323,9e809023890j832e@14fdsffdd")
{
if ($val == "r4r53d323,9e809023890j832e@14fdsffdd")
{return $_SESSION[$var];}
else
{$_SESSION[$var] = $val;}
}

Now, what's that number you ask!... it's just a value which I figured I
would never end up in a real app.
It's just a way for me to use default argument of the function so I can call
_s function with 1 or 2 arguments.

Can this be done a better way? How do you use _s function with 1 or 2
arguments so in 1 arg mode, you can use it as a set, and in 2 arg mode, you
use it as a way to return val.

Is func_get_args route the only way? performance wise which one would
better?




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



[PHP] help in reversing an array

2004-12-25 Thread mail.pmpa
Hi all and Merry Christmas!!

 

I am having some trouble reversing the order of an array.

 

I have this array:

$array[0]='Socket A';

$array[1]='Single processor';

$array[2]='Motherboards';

$array[3]='Hardware';

 

and I want to do a "simple" reverse of the content like this:

$array[0]='Hardware';

$array[1]='Motherboards';

$array[2]='Single processor';

$array[3]='Socket A';

 

Which function amongst the available should I use?

 

Thank you.

 

Pedro Almeida.

 

 



RE: [PHP] How to argue with ASP people...

2004-12-30 Thread mail.pmpa
Don't mean to start a discussion whatsoever, I love php, but one thing i
can't do in php is Response.Redirect .
Apart from that no complains so far :)

* Happy New Year *

Pedro Almeida.


-Mensagem original-
De: Tony Di Croce [mailto:[EMAIL PROTECTED] 
 
I am fairly new to PHP, but I am loving it... I have recently gotten
involved in a business venture and I have been using PHP so far...
Recently I have taken on a partner, and he is a big ASP guy...
(...) 

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



RE: [PHP] How to argue with ASP people...

2004-12-30 Thread mail.pmpa
Can I do any session handling before calling header("Location: $url"); ?

Pedro Almeida.


-Mensagem original-
De: Rasmus Lerdorf [mailto:[EMAIL PROTECTED] 

mail.pmpa wrote:
> Don't mean to start a discussion whatsoever, I love php, but one thing i
> can't do in php is Response.Redirect .
> Apart from that no complains so far :)

header("Location: $url");

which, by the way, makes a hell of a lot more sense.  It's just an HTTP 
response header like any other response header and it is called 
Location, not Redirect.

-Rasmus

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



RE: [PHP] How to argue with ASP people...

2004-12-31 Thread mail.pmpa
I used response.redirect in asp to avoid form re-submit, so I can have form
handling functions and other related functions on the same file.

new_customer_form.php :
< form action="form_results.php" >

Customer fills form and hits submit button.

form_results.php :
function validate_form_data(){
if true show_results();
}
function show_results() {...}

Now customer is on results page in show_results().
If he hits the Refresh button or Back then Forward buttons in he will be
prompt to resubmit the form data or cancel.
If I add header("Location: form_results.php") inside function
validate_form_data() instead of calling function show_results() I can avoid
this behaviour.

I don't know if this is the right procedure, i am learning as I develop.
This was a workaround for shopping cart and customer area form handling form
handling code. Probably I'm doing it all wrong :)

And Robby thanks for the ob_start() tip!

I apologise for my bad English writing.

Pedro Almeida.


-Mensagem original-
De: John Holmes [mailto:[EMAIL PROTECTED] 

Yeah, sure. You just can't have any output before you redirect with a 
Location header (unless you use output buffering as a workaround).

This is basic HTTP and ASP has to play by the same rules. If you can 
have output before Response.Redirect, then ASP is just doing the 
buffering for you before it sends a Location header.
John Holmes...

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



RE: [PHP] How to argue with ASP people...

2004-12-31 Thread mail.pmpa
-Mensagem original-
De: John Holmes

This is a workaround, really. Your code should be structured so that you 
can decide if you need to perform a redirect before any output is sent 
to the browser. If you're going to send them to another page, why would 
you have any output anyhow? Using templates sometimes forces you to do 
this, as you perform all of your business logic / PHP code before hand 
and then display the appropriate templates. If you need to send the user 
to another page, it's easy to do so at any point before your templates 
are shown.
---John Holmes...

Yes you are right, that is what I am doing now, taking all validation /
verification functions that do not output html to top, after session
handling. This is my first php application as I am migrating from asp and
trying to "mirror" my application in php. I have separate php files to
handle different "areas" of the site and like you say I use header+footer
sort of template.

Thanks. Happy New Year!

Pedro Almeida.

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



[PHP] help avoid multiple login

2005-11-28 Thread mail.pmpa
Greetings

I'm having some trouble on a members online script.
I use a php script to track member login to avoid multiple logins on
different ips etc.
When a logged member closes the browser window I can't delete the table
entry because I will not have access to some sort of "Session_OnEnd" action
on hosting.
Is there a workaround for this?

I'm using PHP 5.0.4 and IIS on win XP.

Thanks in advance.
Pedro.

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



RE: [PHP] help avoid multiple login

2005-11-28 Thread mail.pmpa


-Mensagem original-
De: Matt Monaco [mailto:[EMAIL PROTECTED] 
Enviada: terça-feira, 29 de Novembro de 2005 0:02
Para: php-general@lists.php.net
Assunto: [PHP] help avoid multiple login

Create an object with the functionality of your choosing, in the destructor 
perform your cleanup operations.


""mail.pmpa"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Greetings
>
> I'm having some trouble on a members online script.
> I use a php script to track member login to avoid multiple logins on
> different ips etc.
> When a logged member closes the browser window I can't delete the table
> entry because I will not have access to some sort of "Session_OnEnd" 
> action
> on hosting.
> Is there a workaround for this?
>
> I'm using PHP 5.0.4 and IIS on win XP.
>
> Thanks in advance.
> Pedro. 

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

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



RE: [PHP] help avoid multiple login

2005-11-28 Thread mail.pmpa
>De: Matt Monaco [mailto:[EMAIL PROTECTED] 
>Create an object with the functionality of your choosing, in the destructor

>perform your cleanup operations.

The problem is I don't know when a member closes the browser window.
If I knew that i would automatically logout that member.

Thanks.

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



[PHP] help avoid multiple login

2005-11-29 Thread mail.pmpa
-Mensagem original-
De: Jochem Maas
(...)
the normal way of doing session 'closing' is by way of 'garbage collection'
- every now and then a script/process/function is run that 'closes' any
sessions which are (according to your criteria) inactive. php has stuff
built it that will do this for you to a degree.
-

Is there a way I can access sessions from other users on a script?
If yes I could store the session id on a table and later check if isset.

Thanks for replying.
Pedro.

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



[PHP] help avoid multiple login

2005-11-29 Thread mail.pmpa
-Mensagem original-
De: Jochem Maas
(...)
the normal way of doing session 'closing' is by way of 'garbage collection'
- every now and then a script/process/function is run that 'closes' any
sessions which are (according to your criteria) inactive. php has stuff
built it that will do this for you to a degree.
-

Is there a way I can access sessions from other users on a script?
If yes I could store the session id on a table and later check if isset.

Thanks for replying.
Pedro.

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



[PHP] RE: help avoid multiple login

2005-11-30 Thread mail.pmpa
-Mensagem original-
De: Jochem Maas [mailto:[EMAIL PROTECTED] 

>>the normal way of doing session 'closing' is by way of 'garbage
> 
> collection'
> 
>>- every now and then a script/process/function is run that 'closes' any
>>sessions which are (according to your criteria) inactive. php has stuff
>>built it that will do this for you to a degree.
>>-
>>
>>Is there a way I can access sessions from other users on a script?

what exactly do you mean by that last sentence? I don't quite follow it.
--

I mean if I knew all active session id's I could compare them to the
members_online table.

An example in pseudo code:

// Member logs in, store session id, login datetime, last visit datetime:
INSERT INTO members_online

// Get active session ids from table:
php code

// Compare active session ids with table sessions:
for ($i=0; $i < table rows; $i++){
  if ( !isset( session id from member $i )) {
DELETE member from table
  }
}

>>If yes I could store the session id on a table and later check if isset.
>> You could write the session id into a table when the session is started,
>> along with the start time.
>> Something like
>> sessionid CHAR|starttime DATETIME|lastvisittime DATETIME
>> You could then update this table each time the user visits a page, and
>> delete it if the interval between starttime and lastvisittime is longer
than
>> you want. A cron job/scheduled task could be used to clean this table up
>> periodically

>a nice description of 'session garbage collection' :-) 
>which is pretty much all you can do in terms of 'logoff'.


I already use a class to perform this task. The problem is if a member
closes the browser windows and then tries to login again before the
specified timeout.

Does Apache have a function like asp Session_OnStart, Session_OnEnd ?

I am using IIS and PHP 5.0.4

Thanks in advance.
Pedro.

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