SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Next stop: PHP! Marina's Avatar
    Join Date
    Apr 2001
    Location
    Sweden
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What function should I use?

    I'm using this script to write news to a text file. When the news has been sent I'm seeing this message: "News added!". I would like the script to open index.php instead of writing this message. I need to change echo"News added!"; but don't know what function to use. Here's the code:
    PHP Code:
    fopen("news.txt""a+");
    if(
    $action == add){

     
    $fp fopen("news.txt""a+");

        
    $data "$title - $news \n";
        
          
    fputs($fp$data);

            
    fclose($fp);
      echo
    "News added!"

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Two ways:

    1) replace your echo statement with:
    PHP Code:
    header("Location: index.php"); 
    This is the nicest solution but it can be problematic. Absolutely NO output can have been already sent by the script (because this means that the headers will have already been sent). This also means that NO whitespace is allowed before your opening <?php tag (because stuff outside the php tags is treated as raw HTML output). People often get stumped on that.

    2) If you can't get the above to work for you - then you can send a html page with a meta refresh tag
    PHP Code:
    echo '
       <html>
       <head>
          <META HTTP-EQUIV="REFRESH" CONTENT="1; url=index.php">
       </head>
       <body></body>
       </html>
       '


  3. #3
    Next stop: PHP! Marina's Avatar
    Join Date
    Apr 2001
    Location
    Sweden
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks freakysid! You were right, the header("Location: index.php"); didn't work, I just got this message: Warning: Cannot add header information - headers already sent by..... Your other suggestion, however, worked perfectly! Thanks again!


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
  •