Jump to content

Archived

This topic is now archived and is closed to further replies.

xyn

Functions

Recommended Posts

Hey.
I have got a list of functions but I have a problem.
the thing is I forgotte how to call a function and
I don't think the functions been created correctly.

function is:
function Test(){
echo 'test';
}

I can't remember how to call it, I tried call_user_function(Test);
and realised it was wrong! :/

Share this post


Link to post
Share on other sites
[code]
<?php
function Test(){
echo 'test';
}
$post = $_POST['submit'];
if(isset($post)){
Test();
}
?>

<form method="post">
<input type="submit" name="submit">
</form>
[/code]

that would echo test when you push submit.

Share this post


Link to post
Share on other sites
Yeah, I usually do if(isset($_POST['submit'])){
code
}else{
form
}

And i have a logout function which logs out the user
Although my problem is Sessions aren't changing :/.

My function:
function LogOut(){
$_SESSION['LoggedIn'] = false;
$_SESSION['user'] = "";
}

I use:
if( $x = logout ){
LogOut();
}

and nothing, but the redirect in that function works
so does the echo :/

Share this post


Link to post
Share on other sites
You'll want to use this comparing x
[code=php:0]if( $x == 'logout' ){
LogOut();
}[/code]

Otherwise you are assigning $x to the constant logout all the time. Also make sure you have session_start() at the top of your script. And use session_destroy to destroy the session when they logout.

Share this post


Link to post
Share on other sites
I had it $x == "logout" but i'll try session_destroy();
And session_start(); is at the top of the index page where the scripts are included.
:]

Share this post


Link to post
Share on other sites

×

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.