SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, i'm just wondering if it was possible to redirect the user to another page if there was a connection error instead of displaying the die() message?

    for example instead of :

    Code:
    $connection = @mysql_connect($dbhost, $dbuser, $dbpass)
    	or die("The site database appears to be down.");
    can i do something like this ?

    Code:
    $connection = @mysql_connect($dbhost, $dbuser, $dbpass)
    	or Header("Location: /different_page.html");
    just wondering...... thanks
    . . . chris

  2. #2
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    only if you have set NO header info yet... and NO white space has been sent to the browser.. no echo() print() printf() etc. for instance:

    PHP Code:
    <?php
    $connection 
    = @mysql_connect($dbhost$dbuser$dbpass);

    if(!
    $connection){
    header(Location: /different/error.html);
    } else {

    // continue on

    }
    ?>
    would work.. but take this example that wouldn't work:

    PHP Code:
    <html>
    <head>
    <title>My Website</title>
    </head>
    <?php
    $connection 
    = @mysql_connect($dbhost$dbuser$dbpass);

    if(!
    $connection){
    header(Location: /different/error.html);
    } else {

    // continue on

    }
    ?>
    nor would this

    PHP Code:
    <?php

    $connection 
    = @mysql_connect($dbhost$dbuser$dbpass);

    if(!
    $connection){
    header(Location: /different/error.html);


    if(!isset(
    $id)){
    echo(
    "No thread specified");
    } else {

    $sql "SELECT * FROM articles WHERE ID='$id'";
    $result mysql_query($sql);
    if(!
    $result){
    header(Location: /different/error.html);
    }

    while(
    $row mysql_fetch_array($result)){
    echo(
    "$row['Content']");
    }
    }
    ?>
    hope that helps you out some..
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  3. #3
    SitePoint Addict Percipient's Avatar
    Join Date
    Jun 2000
    Location
    Summerland, BC, Canada.
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, you can, as long as it comes before anything that would put contents into the outputted document. If all that has run is a script, and there've been no echo()s, print()s, HTML output, or image generation, it will work.

    Hope that isn't confusing. Here's another wording of it, from the PHP manual...

    Remember that the Header() function must be called before any actual output is sent either by normal HTML tags or from PHP.

    Heh, I was beaten to it, while I was writing this.
    Ed Rands

  4. #4
    Non-Member
    Join Date
    Apr 2000
    Location
    Waco, Texas.
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    atomicmunky, just a quick suggestion: Why not try it out first before asking?
    $connection = @mysql_connect($dbhost, $dbuser, $dbpass)
    or Header("Location: http://www.google.com");

    works fine.

  5. #5
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or you could print out a page with redirect META TAG ,that avoids the problems with Header()
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  6. #6
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the responses you guys.

    robp - i know i coud've tried it before asking but i wanted to know if other people had experience with it. or if there was a better way of doing what i wanted to do.
    . . . chris


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
  •