My php source code do not work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pablo

    My php source code do not work

    Hi at all
    this code it'ld stop and exit if the user do not entered $dbf but it do not
    work
    Why?

    if (!isset($_GET['dbf']) || (isset($_GET['dbf']) && trim($_GET['dbf']) ==
    ''))
    {header('Locati on: http://www.pablo.es/index.php');
    exit();}



  • Erwin Moller

    #2
    Re: My php source code do not work

    Pablo wrote:
    Hi at all
    this code it'ld stop and exit if the user do not entered $dbf but it do
    not work
    Why?
    >
    if (!isset($_GET['dbf']) || (isset($_GET['dbf']) && trim($_GET['dbf']) ==
    ''))
    {header('Locati on: http://www.pablo.es/index.php');
    exit();}
    Hi,

    Look at the logic:
    if
    (!isset($_GET['dbf']) || (isset($_GET['dbf']) && trim($_GET['dbf'])== ''))

    My guess is you ment:
    1) Demand that $_GET['dbf'] is set.
    2) And if set, it must contain something (not empty string)

    The above mixes the || and && is a strange way.

    So try this:
    if ( (isset($_GET['dbf']) && (trim($_GET['dbf']) != '')){
    // OK
    } else {
    // Not OK
    // header and exit.
    }

    You do not need the second isset-test this way.
    When PHP evaluates the first part (isset($_GET['dbf']) to false and sees the
    AND-logic operator && it doesn't even try to evaluate that, because the
    if-statement can never evaluate to true.

    Regards,
    Erwin Moller

    Comment

    • Pablo

      #3
      Re: My php source code do not work

      also this make error

      if (!isset($_GET['dbf']))
      {header("Locati on:http://www.pablo.es"); }

      why?


      Comment

      • Erwin Moller

        #4
        Re: My php source code do not work

        Pablo wrote:
        also this make error
        >
        if (!isset($_GET['dbf']))
        {header("Locati on:http://www.pablo.es"); }
        >
        why?
        Hi,

        I don't know why it makes an error.
        Most probably because your script makes an error somewhere futher down the
        script, because you forgot the exit-command after the header.

        Try this:
        if (!isset($_GET['dbf'])){
        header("Locatio n:http://www.pablo.es");
        exit;
        }

        Remember that PHP can set as many headers as you want, and the script runs
        on and on and on.
        You must stop it yourself by using exit.

        Also, try using brackets {} like I did. It makes the code a lot more
        readable. :-)


        Good luck.

        Regards,
        Erwin Moller

        Comment

        • Jerry Stuckle

          #5
          Re: My php source code do not work

          Pablo wrote:
          also this make error
          >
          if (!isset($_GET['dbf']))
          {header("Locati on:http://www.pablo.es"); }
          >
          why?
          >
          >
          What error do you get? If you get a message about headers already being
          sent, it means you've output something before the call to header(). You
          can't output ANYTHING - not even a blank line - before this call.

          Also, to stop execution here, you need to follow it with

          exit();

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          Working...