ktsirig Posted February 27, 2006 Share Posted February 27, 2006 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 Link to comment https://forums.phpfreaks.com/topic/3711-php-sessions/ Share on other sites More sharing options...
Ge64 Posted February 27, 2006 Share Posted February 27, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/3711-php-sessions/#findComment-12879 Share on other sites More sharing options...
jfnavat Posted April 10, 2009 Share Posted April 10, 2009 You must use:<?php session_start(); ob_start(); ?>You can check this forum:LINK REMOVED. Quote Link to comment https://forums.phpfreaks.com/topic/3711-php-sessions/#findComment-806092 Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 True, but that forum is in spanish... Quote Link to comment https://forums.phpfreaks.com/topic/3711-php-sessions/#findComment-806101 Share on other sites More sharing options...
laffin Posted April 10, 2009 Share Posted April 10, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/3711-php-sessions/#findComment-806102 Share on other sites More sharing options...
corbin Posted April 10, 2009 Share Posted April 10, 2009 [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. Quote Link to comment https://forums.phpfreaks.com/topic/3711-php-sessions/#findComment-806104 Share on other sites More sharing options...
PFMaBiSmAd Posted April 10, 2009 Share Posted April 10, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/3711-php-sessions/#findComment-806106 Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 [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? Quote Link to comment https://forums.phpfreaks.com/topic/3711-php-sessions/#findComment-806107 Share on other sites More sharing options...
corbin Posted April 10, 2009 Share Posted April 10, 2009 Whoa... I didn't notice the date either.Hrmm that forum is his it would seem. So, I bet he wrote that link. Planned? Quote Link to comment https://forums.phpfreaks.com/topic/3711-php-sessions/#findComment-806108 Share on other sites More sharing options...
PFMaBiSmAd Posted April 10, 2009 Share Posted April 10, 2009 He's just posting non-relevant crap to get a link to his site on this forum. I already reported the post. Quote Link to comment https://forums.phpfreaks.com/topic/3711-php-sessions/#findComment-806109 Share on other sites More sharing options...
corbin Posted April 10, 2009 Share Posted April 10, 2009 Which is a ban, yes?;pj/k. Kinda. Quote Link to comment https://forums.phpfreaks.com/topic/3711-php-sessions/#findComment-806110 Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 [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! Quote Link to comment https://forums.phpfreaks.com/topic/3711-php-sessions/#findComment-806112 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.