Jump to content

jimfog

Members
  • Posts

    1,803
  • Joined

  • Last visited

Posts posted by jimfog

  1. The mistake I was doing is that I called only session_start and used the name of the variable($username) instead of $_session[.....]which is the correct in the function above.

  2. The statement
    $_SESSION['valid_user']=$username;

    adds a copy of the value of $username into "$_SESSION['valid_user']". It does NOT make the variable $username itself available to other pages. So if you want to read that value, you have to read the appropriate $_SESSION variable, since that's the only thing your script has access to. For example:

    session_start();    <?php output_header('output_header_list',$_SESSION['valid_user']);

    Ok, how am I going to make the variable $username available to the other pages also by using session functionality?This is what is required here.Unless, session functionality is not required here-and the example you gave me will do the job.
  3. I managed the solve the path issue-I had to make some adjustment at php.ini. Nonetheless there still is an issue.Here is the code in the first page-that sets the session:

    session_start();		   $_SESSION['valid_user']=$username;

    The problem is in the second page-different of course from the one above, not related with the sessio path-here is the code:

    session_start();   <?php output_header('output_header_list',$username);

    I expected that $username would be valid and within the header code(not shown here) the username of the user would be printed, as this is what I am trying to achieve. Here is the error message I get:

    Notice: Undefined variable: username in C:\Apache24\htdocs\Appointments\Administrator\Calview.php on line

    Probably I do not do something correct-but what?

  4. Yep...errors are beginning to come.

    [size=4][color=#333333][font=Monaco, monospace]Warning: session_start(): open(/tmp\sess_gc90vh0m8diqtgfbtvm3ococq5, O_RDWR) failed: No such file or directory (2) in C:\Apache24\htdocs\Appointments\Administrator\adminmember.php on line[/font][/color][/size]

    The funny thing is that at the page where the above message appears session functionality DOES WORK. Let us focus on the above for now, I do not want to go to the messages in subsequent pages-which might be irrelevant to the session problem. I will show the other message errors also if needed-I just do not want to overload us for now. As I side note: Is it maybe better if-when developing to have the errors set to E_ALL?

  5. Οk...the reasons I asked about php.ini that I have problem implementing session control.Let me explain:In one page the session works(in the page where I set the session variable equal to the username).In fact I use the test code below to verify that everything is OK:

    echo 'the content of the session variable is'.$_SESSION['valid_user'] ;

    The problem appears in another page where the session variable IS NOT "kept" by PHP.There I use again session_start() to initiate the session but the session variable seems inactive-I used the test code above to verify it. below is the code I used in the 2 pages:

        $username=$_POST['username'];		   $passwd=$_POST['password'];		   session_start();		    $_SESSION['valid_user'] = $username;   try{ if (!filled_out($_POST))	  {    throw new Exception('Ουπς, δεν συμπληρώσατε τα στοιχεία -πίσω στην φόρμα λοιπόν για να τα συμπληρώσετε.');	   } 	  	   if ($username && $passwd) {		// they have just tried logging in	     login($username, $passwd);  	    output_header('output_header_list',$username);?>	 <div   id="wrap">	    <?php output_buttons();    echo 'the content of the session variable is'.$_SESSION['valid_user'] ;    ?>

    The session above works perfectly fine-in the page below it does not work:

    <?php require_once 'output_functions_admin.php';   session_start();    ?>    <body>	   	    <?php output_header('output_header_list',$username);			    ?>	    <div   id="wrap">		    <?php output_buttons();		    echo 'the content of the session variable is'.$_SESSION['valid_user'] ;		  ?>

    The 2 code segments listed above(from 2 respective pages) it is only a portion of the whole scripts.I just included that piece of the code that will be enough for coming to a solution/conclusion.

  6. So far we have not touched the issue of cookie/URL method for storing the session ID. The question is what is the preferred method forstoring the session ID according to your opinion. And another thing:I have installed PHP manual and as such I have not made any adjustments regarding session in php.ini. What do I have to do?

  7. No. The very idea of the "if" is to prevent exactly THAT scenario. When output_header gets called, it checks if it can call the inner function, and calls it only if it can. A boolean false does not translate to a function that can be called, so no function is ever called within output_headers in that case.
    The thing that confused my is that the Is_callable had as an argument $function.We can use anything there provided that it is something that cannot be called. I used this for example:
    if (is_callable('tel')) {    $function($username);

    and it still did the job.

  8. Because if $function is not callable, then the condition evaluates to false and it never tries to run the function.
    Now I got it.There is one slight details though yet to complete the picture... We said $function is not callable-nonetheless, when output_header gets called, don;t we also call the inner function function(username) (by setting its value to false)which gave us the error and sparkled this all discussion? I hope you understand what I am talking about.
  9. Let us see the code:

    function output_header($function=false,$username=false) {?><div id="header">	  <div><a href="http://localhost/Appointments/Administrator/">			 <img src="Images/logo.png" width="307" height="32" /></a></div>    <?php if (is_callable($function)) {    $function($username);} ?>  </div><?php}

    if the argument $function is a function then the output of that if statement would be $function($username);I do not understand how this stops the error from appearing. I don't get it...

  10. I am getting now somewhere, nonetheless I am surprised that $function($username) is treated like a function,given the fact I put dollar sign in front of it, which means the purpose was to have it treated like a variable. Now we I must find the solution to the problem...callable etc.

  11. well, what do you expect to happen when you set the default value of $func to false, and then try to call it like a function?
    A small comment here.I set it to false because I assumed that $func is considered an argument of output_header. And arguments in PHP function CAN be set to false. And when you say "call it like a function"-you mean output_header() or output_header('output_header_list',$username) I assume you are referring to the first call.
  12. yo must have to match the declaring parameter numbers and calling parameter numbers, unless you are using any default value for any parameters. and if you want to use any variable function as callback. the value of variable must fullfill the criteria of valid function names.
    I really cannot find where is the error here,here are the functions:
    function output_header($function=false,$username=false) {?><div id="header">	  <div><a href="http://localhost/Appointments/Administrator/">			 <img src="Images/logo.png" width="307" height="32" /></a></div>	 <?php  $function($username); ?>    </div><?php}function output_header_list($username){?>     <ul id="headelem">    <li><?php echo $username ?></li>	 <li><a href="calendar.php">Calendar</a></li>    <li><a href="login.php">log in</a></li>    <li><a href="register_form.php">register</a></li>    </ul> <?php   }

    This works well:

    output_header('output_header_list',$username);

    This does not:

    output_header() ;

    I get the message I say above.As you see output_header gets declared with 2 arguments set at a default value of false-so there should not be a problem with calling the function withour arguments. According to the error message the problem lies at $function($username)-this is where the mistake is. But as I understand the above is needed(the way its syntax is) when calling output_header('output_header_list',$username);

  13. output_header_list() should have return something when yo you pass it to output_header(). output_header(output_header_list($username));it tells that use whatever output_header_list() is returning, as first parameter of output_header(). if it does not return anything it will be considered as null (value of first param of output_header()
    So you are saying that in order for a function to be passed as an argument it MUST return something.Ok how am I going to "return" that html ul list in output_header_list-how exactly am I going to use the return keyword-from a syntax point of view?
    Right. You're not passing that function as an argument, you are running the function (which is why it displays that HTML code first), and then passing the return value of the function. It doesn't return anything, so you're passing a null value to the function. In PHP you pass the function name as a string and then use the variable as if it were a function:
    output_header('output_header_list', $username); function output_header($func, $param){  ...  $func($param);  ...}

    Your code works fine,nonetheless it is first time i see a function passed as an argument/string. Do we do this when the function we want to pass as a n argument to another function DOES not return something. There is a problem though... I call output_header 2 times in my script, one with arguments and one without. When it is with arguments(the code you gave ) it is ok.But with no arguments, I get the following error:
    Fatal error: Function name must be a string in C:\Apache24\htdocs\Appointments\Administrator\output_functions_admin.php on line 443

    when i wrote the function, I set the arguments to false so as not have any errors when it is called without them:

    function output_header($output_header_list=false,$username=false) {?><div id="header">	  <div><a href="http://localhost/Appointments/Administrator/">			 <img src="Images/logo.png" width="307" height="32" /></a></div>	 <?php  $output_header_list($username) ?>    </div><?php}

    What can we do?

  14. There's nothing inherently wrong with calling functions from other functions. In fact, calling functions is a basic part of functional or procedural programming. I'm suggesting that PHP might be outputting that HTML straight away instead of waiting until the function is called based on the fact that your screenshot shows those elements in the same order they appear in the code despite the fact that the second function that is defined gets called first. And also because the second function is definitely not calling the first function, I don't see that first function being called anywhere. This line: <?php $output_header_list ?> does not call a function. In fact, it doesn't do anything.
    Here is the call-not shown in the example depicted in the beginning of the post:
    output_header(output_header_list($username));

    With the above code, when output_header gets called, output_header_list($username)(which is the second function) gets passed as an argument. What do you think now?

  15. In php.ini I found 2 display_error entries. I set them both to 1. Nonetheless no error message appears.So, I have 2 questions:1. Do I need to make other adjustments in php.ini-related to the display of errors.2.Is it certain that PHP outputs error when a non-existent file is "required"?

  16. In php ini I found the following: ; display_errors=0; Default Value: Off; Development Value: On; Production Value: Off Which of the above I must uncomment? I will un comment display errors, as you suggest.

  17. You're not calling that other function correctly, but it sounds like it is outputting the HTML before the functions get called. Replace the output with a call to echo a heredoc and see if that makes a difference.
    You're not calling that other function correctly, but it sounds like it is outputting the HTML before the functions get called. Replace the output with a call to echo a heredoc and see if that makes a difference.
    Are you suggesting(if understand correctly) that I do not call a function in a function and just use echo statements?
  18. I might as well post in the html forum... The problem I am facing is that calling a function within a function messes with the html. Here is the code where the html is OK:

    function output_header($username=false) {?><div id="header">	 <div><a href="http://localhost/Appointments/Frontend/"><img src="Images/logo.png" width="307" height="32" /></a></div>	 <ul id="headelem">    <li><?php echo $username ?></li>	 <li><a href="calendar.php">Calendar</a></li>    <li><a href="login.php">log in</a></li>    <li><a href="register_form.php">register</a></li>    </ul></div><?php}

    And here is the code where the html is messed, a function is called inside a function, so below you will see 2 functions:

    function output_header_list($username){    ?> 	 <ul id="headelem">    <li><?php echo $username ?></li>		    <li><a href="calendar.php">Calendar</a></li>    <li><a href="login.php">log in</a></li>    <li><a href="register_form.php">register</a></li>    </ul> <?php   }function output_header($output_header_list=false) {?><div id="header">	  <div><a href="http://localhost/Appointments/Administrator/">			 <img src="Images/logo.png" width="307" height="32" /></a></div>	 <?php  $output_header_list ?>    </div><?php}

    The problem is that instead of ul id="headelem" appearing within div id header(as depicted it the function output header) it appears out of it. Here is the image-from firebug:https://skydrive.live.com/redir?resid=BE27434B2AAC8130!243 Why the above happens?

  19. Ι managed to find where the error was. I was requiring(require_once) a nonexistent file(had forgotten creating it). IF this counts as an Xdebug bug than I do not like the fact that the debbuger gives no indication at all there there is a fatal error. You are saying also that in order to find the exact error I must run the page without xDebug-I am assuming you mean, to run the script in Netbeans, because, when the page loads in the browser, I do not think XDebug has any effect on it-XDebug works only with in the "constraints" of the IDE. Yes it is easy sometimes to find error without message-as this is what I did in this case. And lastly, you are saying that I could see a message when a fatal error, how I can code that?By error logging I suppose you mean PHP error logs. Do these logs record all fatal errors?

×
×
  • Create New...