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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.