Jump to content

PHP sessions...


ktsirig

Recommended Posts

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?
Link to comment
Share on other sites

[!--quoteo(post=350045:date=Feb 28 2006, 12:09 AM:name=ktsirig)--][div class=\'quotetop\']QUOTE(ktsirig @ Feb 28 2006, 12:09 AM) [snapback]350045[/snapback][/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.
Link to comment
Share on other sites

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

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

I think is what he is referring to.

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

pretty nice idea overall.
Link to comment
Share on other sites

[quote author=Maq link=topic=87000.msg1156497#msg1156497 date=1239333862]
True, but that forum is in spanish...
[/quote]

[quote]
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.
[/quote]

My terrible Spanish in action:

[quote]

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.
[/quote]


I've no idea why it has ob_start() in there.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[quote]A) The thread was probably solved three years ago,[/quote]

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?
Link to comment
Share on other sites

[quote author=PFMaBiSmAd link=topic=87000.msg1156505#msg1156505 date=1239334891]
He's just posting non-relevant crap to get a link to his site on this forum. I already reported the post.
[/quote]

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

Good luck with your advertising technique!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.