Jump to content


Photo

Functions


  • Please log in to reply
5 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 12 August 2006 - 03:31 PM

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! :/

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 12 August 2006 - 03:32 PM

Test();
~ D Kuang

#3 Demonic

Demonic
  • Members
  • PipPipPip
  • Advanced Member
  • 562 posts

Posted 12 August 2006 - 04:05 PM

<?php
function Test(){
echo 'test';
}
$post = $_POST['submit'];
if(isset($post)){
Test();
}
?>

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

that would echo test when you push submit.

#4 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 12 August 2006 - 04:21 PM

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 :/

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 12 August 2006 - 04:26 PM

You'll want to use this comparing x
if( $x == 'logout' ){
LogOut();
}

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.

#6 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 12 August 2006 - 04:36 PM

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.
:]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users