Jump to content

session security isn't forwarding to login


turpentyne

Recommended Posts

I'm trying to create a simple session on a form page that determines if you've signed in. If you haven't, it kicks you to the login page. But for some reason, what I have isn't doing that. When I open the page, it loads, but only prints the url on a blank page, instead of actually going to the url.

 

<html>
<title>form</title>
<link rel="stylesheet" type="text/css" href="style.css"> 
<body>

<?php
session_start();

if(isset($_SESSION['id']) && is_numeric($_SESSION['id'])) {
      

if (isset($_POST['submitted'])) {
$errors = array();


if (empty($_POST['scientific_name'])) {
$errors[] = 'you forgot to enter the scientific name';

} else {
$sn = trim($_POST['scientific_name']);
}

if (empty($_POST['common_name_english'])) {
$errors[] = 'you forgot to enter the common name';

} else {
$cne = trim($_POST['common_name_english']);
}

$description4 = trim($_POST['common_names_spanish']);
$description5 = trim($_POST['common_names_french']);
$description6 = etc. etc.

if (empty($errors)) {

require_once ('3_z_mysq1_c0nn3ct.php');

$query = "INSERT INTO plantae (scientific_name, common_name_english, etc.)
VALUES ('$sn', '$cne', '$description4', '$description5', '$description6', '$description7', etc.)";

$result = @mysql_query ($query);


if ($result) {

if(isset($_POST['scientific_name']))
{
$plant_id=mysql_insert_id();
}


exit();
} else {
echo 'system error. No plant added';

echo '<p>' . mysql_error() . '<br><br>query:' . $query . '</p>';


exit();

}
mysql_close();

} else {

echo 'error. the following error occured <br>';
foreach ($errors as $msg) {

echo " - $msg<br>\n";

}

} // end of if

} // end of main submit conditional


echo '<form action="insertaplant1.php" method="post"><fieldset><legend><b>Enter your new plant here</b></legend>


form fields here.

</form>'; 
      } else { 
       
      $url = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);

if((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
          $url = substr($url, 0, -1);
        }

$url .= '/login.php';

echo $url;
     
       exit(); 
       }

?>

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.