ulrisa
Posts: 8
|
| Posted: 07/06/2008, 9:22 AM |
|
I have an variable deletecookie that i want to use for, of course, log out .
$Tpl->SetVar('deletecookie',setcookie('TidbokningLogin','',time()-3600));
My problem is how shall i access it from the template file ice tried this
<a href="{deletecookie}>Logout</a>
but its not working what can i use.
Need help 
Ulrik
|
 |
 |
datadoit
|
| Posted: 07/06/2008, 3:21 PM |
|
You'll want to do is try to use CodeCharge's built-in Logout link (under
the Authentification Builder). If that's not possible, try something like:
$Tpl->SetVar("deletecookie", "<?php
setcookie('TidbokningLogin','',time()-3600); ?><a
href='YourPage.php'>Logout</a>');
then just put {deletecookie} in your HTML wherever you want the Logout
link to display. See if that works.
|
|
|
 |
jjrjr1
Posts: 942
|
| Posted: 07/06/2008, 5:16 PM |
|
Hi
Datadoit, I am not to sure that will work. I have tried to place <?php some code ?> into the HTML templates and they do not execute. Have you done it and make it work?
What I have done to accomplish this is create a CCS file called logout.
It is a blank file with in the before show event it simply does a logout function.
Seems to work fine.
This way his $Tpl replace could work by having the {logout} value in the template for the href be logout.php.
eg: $Tpl->SetVar("logout","logout.php");
Have fun
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
ulrisa
Posts: 8
|
| Posted: 07/06/2008, 11:59 PM |
|
Hi, it did not work for me either.
I had to do it somelike the way jjrjr1 desribes, a redirect to a logout.php.
$Tpl->SetVar("logga out","logout.php");
Which just contains a setcookie and a redirect back to my index file.
But it would be useful to be able to execute PHP directly.
Ulrik
|
 |
 |
ulrisa
Posts: 8
|
| Posted: 07/06/2008, 11:59 PM |
|
Hi, it did not work for me either.
I had to do it somelike the way jjrjr1 desribes, a redirect to a logout.php.
$Tpl->SetVar("logga out","logout.php");
Which just contains a setcookie and a redirect back to my index file.
But it would be useful to be able to execute PHP directly.
Ulrik
|
 |
 |
datadoit
|
| Posted: 07/07/2008, 5:43 AM |
|
jjrjr1 wrote:
> Hi
>
> Datadoit, I am not to sure that will work. I have tried to place <?php some
> code ?> into the HTML templates and they do not execute. Have you done it and
> make it work?
>
> ---------------------------------------
Tested and it doesn't work here either. I'm sure there's a logical
reason why that wouldn't or more importantly -shouldn't- work.
If you have PHP code loading in HTML code, and you allow that HTML code
to load in more PHP code - I can imagine that would be a bad thing. I
just don't know why yet. :)
|
|
|
 |
datadoit
|
| Posted: 07/07/2008, 5:46 AM |
|
As stated earlier, you should use CodeCharge's built-in authentification
features if possible. No coding required! All of the session
management is done for you.
|
|
|
 |
jjrjr1
Posts: 942
|
| Posted: 07/07/2008, 7:48 AM |
|
Hi
I think the reason php in the html does not work is that the html we edit is a template that CCS used to generate the content. Somehow I think that is related but I do not understand why.
Like I said I have tried to put php directly into the HTML and it never works. You think it should because if you view the source of the code containing the <? ,,,, ?> when running in the browser you will see the seemingly unexecuted code in the source.
I have never really explored why it does not work that way sonce you can do most anything you want in the php code that drives the HTML.
Too Wierd Though.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/07/2008, 9:07 AM |
|
Hi
I now think I know why PHP code <? ,,,, ?> cannot be put into CCS templates.
I suspect it is the way CCS uses PHP output buffers. All the HTML content is generated into the $Tpl object. This is where CCS puts all the control info, text, and all that the page will output using the html template. By the time CCS is ready to display the page it has created it and has placed into the global string $main_block.
To display the page CCS simply outputs the string $main_block. Since that is how the page is displayed the output is sent directly to the client browser and the HTML does not have any ability to perform any more server side processing. (The PHP code between <? .. ?> must execute at the server), SInce the page has been sent to the client as a string, only client side processing can be done such as javascript, html, etc.
I think that explains this issue.
ANy thoughts?
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/07/2008, 9:22 AM |
|
A way to prove this, if anyone wants to, is try...
Create a CCS page. Place some <? PHP Code ?> into the template.
In the before output event take $main_block and write it to a file with an html extention like so.
global $main_block;
if ($TmpFH = @fopen("temp.html", "wb")) {
fwrite($TmpFH, $main_block);
fclose($TmpFH);}
After that code force a load of that page like so:
header("HTTP/1.1 302 Found");
header("Location: temp.html");
exit;
I bet the page will display and the PHP code will execute.
If you try it, let me know if it works.
Have fun,
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
datadoit
|
| Posted: 07/09/2008, 8:15 AM |
|
Makes perfect sense! Good job. Keep this info handy for the wiki that
Yes will have published sometime before 2020.
|
|
|
 |
|