kazsil Posted September 30, 2007 Share Posted September 30, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/71215-solved-what-i-cant-use-a-function-in-an-ifelse/ Share on other sites More sharing options...
tibberous Posted September 30, 2007 Share Posted September 30, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/71215-solved-what-i-cant-use-a-function-in-an-ifelse/#findComment-358199 Share on other sites More sharing options...
RichardRotterdam Posted September 30, 2007 Share Posted September 30, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/71215-solved-what-i-cant-use-a-function-in-an-ifelse/#findComment-358201 Share on other sites More sharing options...
markjoe Posted September 30, 2007 Share Posted September 30, 2007 I think it is a good idea to always use exit() after header(). Even if it doesn't fix it, you will know for sure what is happening at the IF. Quote Link to comment https://forums.phpfreaks.com/topic/71215-solved-what-i-cant-use-a-function-in-an-ifelse/#findComment-358293 Share on other sites More sharing options...
kazsil Posted October 9, 2007 Author Share Posted October 9, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/71215-solved-what-i-cant-use-a-function-in-an-ifelse/#findComment-365112 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.