Jump to content

[SOLVED] Need some help w/ redirecting


jscix

Recommended Posts

Ok, my question is:

How do I stop the content of a script from loading and instead; redirect to another page based on criteria performed in a seperate script, that is php included from within the original script?

 

The problem is, the included script which supplies the criteria for whether or not the content should load, must be included after some session, and error handeling code.. which prevents me from redirecting,

and as far as I am aware, prevents the code ABOVE the INCLUDE, from being able to read any variables that are set within the included file, since they have no value until the included script sets them.

 

Is there any way around this, or am I going to have to redesign the way the script works??

 

Here is the login script - Which at the bottom includes display.php

<?php

session_start();
$xxxy = (isset($_SESSION['userrname']));

if ($xxxy == "1")
{

    include ('db_connect.php');
    $connection1 = mysql_connect($db_host, $db_username, $db_password);
    if (!$connection1)
    {
        die ("Could not connect to the database: <br />" . mysql_error());
    }
    $db_select = mysql_select_db($db_database);
    if (!$db_select)
    {
        die ("Could not select the database: <br />" . mysql_error());
    }
    $uhusr = ($_SESSION['userrname']);

    $sql2 = "SELECT * FROM `" . $uhusr . "` LIMIT 0, 30 ";
    $duh2 = mysql_query($sql2);

    $res2 = mysql_fetch_row(($duh2));
    $latl = ($_SESSION['passwordd']);

    if ($res2[0] == $latl)
    {

        print "<center />You are already logged in <a href=index.php />click here</a 

/><br />";

        die ();
    }

    if (!duh2)
    {
        die ("Username does not exist.");
    }

}
else
{
}
?>

<html>
<center>
<img src="/PHP/Test/login.jpg"><br>

<?php
include "forms.php";
$ohno2 = include ("parse.php");

$dbusr1 = ($_POST["usrfeild"]);
$dbpw1 = ($_POST["pwfeild"]);
// Validatestr is called from within parse.php
$usrf1 = Validatestr($dbusr1);
$pwf1 = Validatestr($dbpw1);

if ($dbusr1 == (null))
{
    print "Please enter a username and password to continue.";
    die ();
}
elseif ($dbpw1 == (null))
{
    print "Please enter a username and password to continue.";
    die ();

}
elseif ($usrf1 == "")
{
    print $usrf1 . "<br />";
    print "Usernames must start with a letter!";
    die ();

}
elseif ($pwf1 == "")
{
    print $pwf1 . "<br />";
    print "Passwords must start with a letter!";
    die ();

}
elseif ((strlen($dbusr1) < 3))
{
    print "Usernames must be at least 3 characters.";
    die ();

}
elseif ((strlen($dbpw1) < 3))
{
    print "Passwords must be at least 3 characters.";
    die ();
}
else
{
    include "display.php";
}

?>

</center>
</html>

 

 

 

Here is the display.php script --  At the bottom is a print "thanks for logging in click here" message, Instead of this I would like to either redirect or set a variable that can be read from the loginscript and redirect from there...

<?php

include ('db_connect.php');

$connection = mysql_connect($db_host, $db_username, $db_password);

if (!$connection)
{
    die ("Could not connect to the database: <br />" . mysql_error());
}

$db_select = mysql_select_db($db_database);
if (!$db_select)
{
    die ("Could not select the database: <br />" . mysql_error());
}

$sql = "SELECT * FROM `" . $dbusr1 . "` LIMIT 0, 30 ";

$duh = mysql_query($sql);

if (!$duh)
{
    die ("Username does not exist.");
}

$result = mysql_fetch_row(($duh));

$retpass = $result[0];

$pwmd5 = (md5($dbpw1));

$name1 = $pwmd5;
$name2 = $retpass;

$result = strcasecmp($name1, $name2);

if (!$result)
{

    $_SESSION['userrname'] = $dbusr1;
    $_SESSION['passwordd'] = $pwmd5;

    print "<center />Thanks for logging in $sbusr1 <a href=index.php />click here</a />";
    mysql_close();
    die ();
}
else
{
    echo "You have entered an incorrect password.";
    mysql_close();
    die ();
}

mysql_close();

?>

Link to comment
Share on other sites

ob_start and ob_end_flush(); are not a solved problam really you need to find out why theres an error ok?

 

I reacon that you have got html before the header infromation ok.

 

good luck

 

ps.All you need to remember is that ob_start is not the best statement to stop header errors ok.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.