Jump to content


Photo

PHP sessions...


  • Please log in to reply
11 replies to this topic

#1 ktsirig

ktsirig
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 27 February 2006 - 11:09 PM

Hi everybody!
I have a problem and I was told to check out the sessions part in PHP.
What I want to deal with is the following :
I have a PHP page with a form, where the user writes some data. These data are then written into a file which is then used in a system command as input for an external program (NOTE: The data MUST be written into a file, it cannot be done elsewhise, because the external program takes a file as input).
The thing is that I must somehow create a file everytime a user enters data into the form, so I must learn something on sessions I think.
My question is, since I don't have a login system or something like that, but just want to create a different file each time (with the session_id being part of it, so that the file is unique), which session commands do I need?

#2 Ge64

Ge64
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 27 February 2006 - 11:13 PM

[!--quoteo(post=350045:date=Feb 28 2006, 12:09 AM:name=ktsirig)--][div class=\'quotetop\']QUOTE(ktsirig @ Feb 28 2006, 12:09 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hi everybody!
I have a problem and I was told to check out the sessions part in PHP.
What I want to deal with is the following :
I have a PHP page with a form, where the user writes some data. These data are then written into a file which is then used in a system command as input for an external program (NOTE: The data MUST be written into a file, it cannot be done elsewhise, because the external program takes a file as input).
The thing is that I must somehow create a file everytime a user enters data into the form, so I must learn something on sessions I think.
My question is, since I don't have a login system or something like that, but just want to create a different file each time (with the session_id being part of it, so that the file is unique), which session commands do I need?
[/quote]

I dont really think you need sessions here, sessions are for remembering information such as login and password when you move to another page (so the page knows who is logged in). You need the fopen() commands (see www.php.net) and something that makes a unique ID. You could save all the IDs that are used to a file and make a script make up one that isnt in there yet.

#3 jfnavat

jfnavat
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 10 April 2009 - 03:15 AM

You must use:
<?php
session_start();
ob_start();
?>
You can check this forum:
LINK REMOVED.

#4 Maq

Maq
  • Administrators
  • Advanced Member
  • 9,410 posts
  • LocationPennsylvania, USA

Posted 10 April 2009 - 03:24 AM

True, but that forum is in spanish...
tjmothy
ini_set ("display_errors", "1");
error_reporting(E_ALL);

#5 laffin

laffin
  • Members
  • PipPipPip
  • Advanced Member
  • 1,200 posts

Posted 10 April 2009 - 03:31 AM

niy ya can use the session id as a unique file name and retrieve the file easily.

$sessid = session_id();
shell("ls -ratfl > userfiles/{$sessid}.txt");

I think is what he is referring to.

so u can retrieve eash file that the user requested
$sessid = session_id();
$fg = file_get_contents("userfiles/{$sessid}.txt");

pretty nice idea overall.


#6 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 10 April 2009 - 03:35 AM

True, but that forum is in spanish...


Es un problema común para principiantes en PHP el declarar variables de sesión y no poder luego accesarlas desde otra página o programa PHP. Esto se debe a la omisión del uso de: session_start();

<?php
session_start();
ob_start();
?>

Este código debe ser colocado antes de que se envíe información HTML en todas las páginas que deben mantener la sesión.


My terrible Spanish in action:


It is a common problem for PHP coders to declare session variables and later no be able to access them on other pages or in other PHP programs.  This is because of forgetting session_start().

<?php
session_start();
ob_start();
?>


This code should be placed before sending any HTML information in all of the pages that should use session variables.



I've no idea why it has ob_start() in there.
Why doesn't anyone ever say hi, hey, or whad up world?

#7 PFMaBiSmAd

PFMaBiSmAd
  • Staff Alumni
  • Advanced Member
  • 16,767 posts
  • LocationColorado, U.S.A.

Posted 10 April 2009 - 03:37 AM

A) The thread was probably solved three years ago,
B) Writing a file with specific content that is used as input to another application has nothing to do with sessions, because the session data is serialized when it is written and the extra processing to make use of that data would exceed the code necessary to write the file directly.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

#8 Maq

Maq
  • Administrators
  • Advanced Member
  • 9,410 posts
  • LocationPennsylvania, USA

Posted 10 April 2009 - 03:39 AM

A) The thread was probably solved three years ago,


Hahaha, didn't even see the date...

I always click on "Show unread posts since last visit.", and respond.

jfnavat, it's all your fault!!!  j/k  How did you find this thread anyway?
tjmothy
ini_set ("display_errors", "1");
error_reporting(E_ALL);

#9 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 10 April 2009 - 03:40 AM

Whoa...  I didn't notice the date either.


Hrmm that forum is his it would seem.  So, I bet he wrote that link.  Planned?
Why doesn't anyone ever say hi, hey, or whad up world?

#10 PFMaBiSmAd

PFMaBiSmAd
  • Staff Alumni
  • Advanced Member
  • 16,767 posts
  • LocationColorado, U.S.A.

Posted 10 April 2009 - 03:41 AM

He's just posting non-relevant crap to get a link to his site on this forum. I already reported the post.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

#11 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 10 April 2009 - 03:42 AM

Which is a ban, yes?


;p



j/k.  Kinda.
Why doesn't anyone ever say hi, hey, or whad up world?

#12 Maq

Maq
  • Administrators
  • Advanced Member
  • 9,410 posts
  • LocationPennsylvania, USA

Posted 10 April 2009 - 03:44 AM

He's just posting non-relevant crap to get a link to his site on this forum. I already reported the post.


Yes, he most definitely is.  Only has 2 posts but they both reference his/the site...

Good luck with your advertising technique!
tjmothy
ini_set ("display_errors", "1");
error_reporting(E_ALL);




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users