Jump to content

[SOLVED] WHAT?!?! I can't use a function in an If/else????


kazsil

Recommended Posts

OMG@!%#@!  :'(

I am driving myself nuts!  I am trying to fix this session issue that I am having

(any help would be great  http://www.phpfreaks.com/forums/index.php/topic,161256.0.html )

 

I thought I would use a simple IF Else Statement and check for the session var then if it is not set, run the rest of my page.... not sure if that is even a good fix but I am trying to test it and CANT... GRRRRRR.

 

Here is what I have

if(!isset($_SESSION['Party_ID'])){
    $msg = "Your session has expired.  Please log back in.";
    header("Location: login.php?msg=".$msg);
}else{

///REST OF MY PAGE PHP&HTML GOES HERE

} //end if else isset

 

When I run the page I get this error

Fatal error: Call to undefined function VechileProfile() in /home/www/carcheckup.com/htdocs/myProfile.php on line 133

 

On line 133 is this line

  VechileProfile();

which is a call to an internal function about 15 rows down.

 

What is so irritating is that it works if i take out the if/else but when i put it back in it blows up with the error.

 

So my question to you gurus....  can i not have a function in an if/else statement?

 

And can any of you fix my other session issue from http://www.phpfreaks.com/forums/index.php/topic,161256.0.html

 

Thanks SO much!!

Jen

If I understand right, you want:

 

if(!isset($_SESSION['Party_ID'])){
    $msg = "Your session has expired.  Please log back in.";
    header("Location: login.php?msg=".$msg);
}else{
?>
Here is your html.
<?php
}
?>

 

And die after you do the redirect header.

 

And for testing, you probably want redirects off - as it sometimes easy to get bounced around.

 

On line 133 is this line

  VechileProfile();

which is a call to an internal function about 15 rows down.

 

why not just place that function higher? The error just states that your calling a funtion that does not (yet) exist.

  • 2 weeks later...

THis is how i solved this problem and my other problem... dont know if it is right, but it is working for me.

 

 

The code I ended up using was this...

I made it an include on every page

 

********************************************************
FUNCTION SessionStart(){
        //// this defines the session timeout  ///////////
        /// this gets started on login2.php  when the login is validated ////
define('SESSION_TIMEOUT', 60);    //sets minutes
$_SESSION['timeout'] = (time() + (SESSION_TIMEOUT * 60));  //sets the timeout to now plus minutes X 60 sec

}//end session funciton



FUNCTION PageSession(){
    global $msg;
if(time() > $_SESSION['timeout']){
    // User's session has expired.  Go back to the login screen.
    $msg = "Your session has expired.  Please log back in.";
    return header("Location: login.php?msg=".$msg);
    exit;
}// end if
          ///if the session var timeout is still alive, reset the timer
if(isset($_SESSION['timeout'])) {
    $_SESSION['timeout'] = (time() + (SESSION_TIMEOUT * 60)); //session_timout is set on login2 }//end if


}//END FUNCTION

Archived

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

×
×
  • Create New...

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.