SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    header("Location: newloc.php"); and code execution

    OK, for example, I have news database. There I have abitily to delete those news. For this I have file del.php which starts with:
    PHP Code:
    <? header("Location: shownews.php"); ?>
    ...and goes on with commands for deleting data from database.

    Newbie like I am, I'd like to know, how this is possible that before sending browser to new page (shownews.php), it executes commands for deleting data from database.

    Just curious to know why it is so...

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because the header() call ends the script so your delete stuff doesn't happen. A solutiopn move the header(0 call to after the delete stuff happens, just remember not to have any html or whitespace(outside of <? ?> tags) above the header() call or it will break.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, no, everything happens like I want. The problem is, how.
    For, me, as I understand it, it should only execute the header(), not this script for deleting data.

    It's mechanism I'd like to know

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put an
    PHP Code:
    exit; 
    after the header

    PHP Code:
    <?
    header
    ("Location: shownews.php");
    exit;
    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, i know that...
    Maybe it's because my bad english that I can't explain my problem well...
    Fo me, header("Location: ...") should redirect only, not execute below code (it's not so, I know, but why). Thats the thind i'd like to know... huhh...

    ---
    My confusing expressing

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like I just said, I don't know, but if you put an exit; right after the header() call it will keep the rest of the script from executing.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    He is saying that even though the header is at the top it still executes the rest of the code, and he wants to know why its is executing code.

  8. #8
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because like freddy said you need to use exit;

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •