Jump to content

Help me with a header plz


k3n3t1k

Recommended Posts

Could you look at this code and tell me what you think would cause the page not to foward to the header?

 

 

<?php
session_start(); ?>
<html>
<head>
<title>
Login
</title>
<body>
<?php
require_once "dbconfig.php";

$sql = mysql_query("SELECT * FROM studentcenter WHERE username='"($_POST['username'])."'")
or die("Username is Incorrect  ".mysql_error());
/* Check if Username Exists */

$results = mysql_fetch_array($sql)
or die("Error at results section: ".mysql_error());
/* Puts database information into an array */

if($result['password'] == $_POST['password']) {
/* Checks if passwords match */

/* Start Session */
header ("Cache-control: private");
$SESSION['sessionname'] = $_POST['username'];
session_name($SESSION['sessionname);
session_id([id]);
echo("Welcome, Forwarding");
header("location: studenthome.php?id")
or die("Will not foward" .mysql_error());
}else{
echo "Incorrect Login, please try again or <a href="register.php">Register</a>";
}
?>
</body>
</html>

 

Thanks,

k3n3t1k

Link to comment
Share on other sites

<?php
header ("Cache-control: private");
$SESSION['sessionname'] = $_POST['username'];
session_name($SESSION['sessionname']);
session_id([id]);
echo("Welcome, Forwarding");
header("location: studenthome.php?id")
or die("Will not foward" .mysql_error());
}else{
echo "Incorrect Login, please try again or <a href="register.php">Register</a>";
}
?>

Link to comment
Share on other sites

Well, first off you have a syntax error that darkfreaks fixed.

 

Secondly, you're using the wrong variable for sessions; try $_SESSION instead of $SESSION.

 

Thirdly, you are echo'ing output before your call to header().  You must never do this.  Headers have to be sent before any output; nothing can come before headers, not even white space.  You'll have to restructure your logic to fix that.

 

Fourth, if you want to redirect with a header('Location: ...') then you must call exit(); afterwards or your script will keep processing.

Link to comment
Share on other sites

Is this what it should look like after those errors?

 

<?php
header ("Cache-control: private");
$_SESSION['sessionname'] = $_POST['username'];
session_name($SESSION['sessionname']);
session_id([id]);
header("location: studenthome.php?id");
exit();
echo("Welcome, Forwarding");
or die("Will not foward" .mysql_error());
}else{
echo "Incorrect Login, please try again or <a href="register.php">Register</a>";
}
?>

Link to comment
Share on other sites

<?php
header ("Cache-control: private");
$_SESSION['sessionname'] = $_POST['username'];
session_name($_SESSION['sessionname']);
session_id([id]);
header("location: studenthome.php?id");
exit();
echo("Welcome, Forwarding");
or die("Will not foward" .mysql_error());
}else{
echo "Incorrect Login, please try again or <a href="register.php">Register</a>";
}
?>

 

still forgot the underscore in session  :P

Link to comment
Share on other sites

<?php
header ("Cache-control: private");
$_SESSION['sessionname'] = $_POST['username'];

// In the following line you may mean $_SESSION['sessionname'], although I'm not sure
session_name($SESSION['sessionname']);

// What in the Hell is [id]?
session_id([id]);

// It doesn't look to me as if you finished your query string...?id=the_id
header("location: studenthome.php?id");
exit();

// Next line is pointless, you'll have already exited and redirected (you'll never see the message)
echo("Welcome, Forwarding");

// What is this or die() attached to?
or die("Will not foward" .mysql_error());

// Is there more code above this? or do you just have a random }else{ floating around
}else{
echo "Incorrect Login, please try again or <a href="register.php">Register</a>";
}
?>

Link to comment
Share on other sites

I tried the suggestions above to no avail.

 

I probabbly should have posted this before but there is more code, here is the entire page:

 

<?php
session_start(); ?>
<html>
<head>
<title>
Login
</title>
<body>
<?php
require_once "dbconfig.php";

$sql = mysql_query("SELECT * FROM studentcenter WHERE username='"($_POST['username'])."'");
/* Check if Username Exists */

$results = mysql_fetch_array($sql);
/* Puts database information into an array */

if($result['password'] == $_POST['password']) {
/* Checks if passwords match */

/* Start Session */

header ("Cache-control: private");
$_SESSION['sessionname'] = $_POST['username'];
session_name($_SESSION['sessionname']);
session_id(1);
header("location: studenthome.php?id=1");
exit();
}else{
echo "Incorrect Login, please try again or <a href="register.php">Register</a>";
}

?>
</body>
</html>

Link to comment
Share on other sites

I put the both headers before anything. It still wont foward.

 

<?php
header("location: studenthome.php?id=1");
header ("Cache-control: private");
session_start();



require_once "dbconfig.php";

$sql = mysql_query("SELECT * FROM studentcenter WHERE username='"($_POST['username'])."'");
/* Check if Username Exists */

$results = mysql_fetch_array($sql);
/* Puts database information into an array */

if($result['password'] = $_POST['password']) {
/* Checks if passwords match */

/* Start Session */


$_SESSION['sessionname'] = $_POST['username'];
session_name($_SESSION['sessionname']);
session_id(1);
/* header("location: studenthome.php?id=1"); */
exit();
}else{
echo "Incorrect Login, please try again or <a href="register.php">Register</a>";
}

?>

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.