[eluser]vas13[/eluser]
Hi to all again,
I have finally chosen to use the build in Session mechanism provided by PHP. I just didn't want to create a table into a DB holding this way the confirmation string at the server side.
Having studied recently PHP, I would like to ask you, the approach I followed regarding where to delete the session data stored at my server. I know it's more a PHP question and not that much related to CI but I think it's worth discussing it anyways
.
I have 2 pages (article_controller, contact_me controller) which contains a captcha image. As a result on those pages (controllers) I create a new session at their constructors.
The question I have it's where to delete this session (I am talking about the file created automatically by PHP) and at the same time where to delete the captcha image.
in the constructor of the above 2 controllers I have the following code
Code:
session_start();
if(isset($_SESSION['captcha_full_path']))
{ if(!unlink($_SESSION['captcha_full_path']))
die("you can't delete the captcha files <br />");
}
So in case a user click on the refresh button or it gives an error verification code the old captcha file can be efficiently deleted.
Afterwards, inside the constructors of all the other pages I've written the following code
Code:
session_start();
if(isset($_SESSION['captcha_full_path']))
{ if(!unlink($_SESSION['captcha_full_path']))
die("you can't delete the captcha files <br />");
$_SESSION[]=array();
}
session_destroy();
So in case that the user goes to a page after having been on a page containing captcha --> the session data will be loaded to the superglobal array $_SESSION, I will delete the image and after that I will delete the session file.
Otherwise, PHP just create and delete a session file.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
My above solution it clears everything both session files created by PHP & captcha images. But It has the disadvantage of creating and deleting a session file every time a user visits a page which dosn't contain Captcha image.
How do you find my approach?? I look forward hearing ideas and thoughts.
Lastly, as for the data stored in every session I create are:
Code:
$_SESSION['confirmation_string']
$_SESSION['captcha_full_path']