Jump to content

[SOLVED] Sessions


andrew6607

Recommended Posts

Hello im getting a error with sessions here it is

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\newsite\member.php:6) in C:\xampp\htdocs\newsite\member.php on line 24

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\newsite\member.php:6) in C:\xampp\htdocs\newsite\member.php on line 24

Welcome

 

And here is the code im using

 

<?php

session_start();

 

// store session data

$_SESSION['username'];

?>

<?php

//retrieve session data

echo "Welcome". $_SESSION['username'];

?>

 

PLEASE HELP!!

Link to comment
https://forums.phpfreaks.com/topic/71755-solved-sessions/
Share on other sites

Nope I dont know whats going on ill send ya the code of the script

 

<?php

$usernamea=$_POST['username'];

$title=$usernamea;

?>

<title>

Welcome <?php echo $title; ?>!

</title>

<?php

include_once("includes/config.php");

mysql_select_db($data,$connect) or die ("Cannot Connect to Database Server");

$username=$_POST['username'];

$password=$_POST['password'];

// Connections

$sql="SELECT * FROM users WHERE username='$username' && password='$password'";

$query=mysql_query($sql);

$row=mysql_fetch_assoc($query);

$totalRow=mysql_num_rows($query);

// If username is correct

if ($username = $row['username']) {

// If password is correct

if ($password = $row['password']) {

?>

<?php

session_start();

session_register('user_id');

// store session data

$_SESSION['username'];

//retrieve session data

echo "Welcome". $_SESSION['username'];

?>

 

<?php

} else {

echo "Password is Incorrect! <a href='index.php'>Try Again</a>";

}

} else {

echo "Wrong Password or the User does not exist! <a href='index.php'>Try Again</a>";

}

mysql_free_result($query);

?>

Link to comment
https://forums.phpfreaks.com/topic/71755-solved-sessions/#findComment-361363
Share on other sites

You Are declaring session_register(); Before your session_register. Try:::

 

<?php
session_start();
$usernamea=$_POST['username'];
$title=$usernamea;
?>
<title>
Welcome <?php echo $title; ?>!
</title>
<?php
require_once("includes/config.php");
mysql_select_db($data,$connect) or die ("Cannot Connect to Database Server");
$username=$_POST['username'];
$password=$_POST['password'];
// Connections
$sql="SELECT * FROM users WHERE username='$username' && password='$password'";
$query=mysql_query($sql);
$row=mysql_fetch_assoc($query);
$totalRow=mysql_num_rows($query);
// If username is correct
if ($username = $row['username']) {
// If password is correct
if ($password = $row['password']) {
?>
<?php
session_register('user_id');
// store session data
$_SESSION['username'];
//retrieve session data
echo "Welcome". $_SESSION['username'];
?>

<?php
} else {
echo "Password is Incorrect! <a href='index.php'>Try Again</a>";
if (session_is_registered('username'){
session_unregister('username')
}
}
} else {
echo "Wrong Password or the User does not exist! <a href='index.php'>Try Again</a>";
if (session_is_registered('username'){
session_unregister('username')
}
}
mysql_free_result($query);
?>

 

Hope this helps Andrew?

Link to comment
https://forums.phpfreaks.com/topic/71755-solved-sessions/#findComment-361371
Share on other sites

Oops sorry error in my code. Try:

 

<?php
session_start();
$usernamea=$_POST['username'];
$title=$usernamea;
?>
<title>
Welcome <?php echo $title; ?>!
</title>
<?php
require_once("includes/config.php");
mysql_select_db($data,$connect) or die ("Cannot Connect to Database Server");
$username=$_POST['username'];
$password=$_POST['password'];
// Connections
$sql="SELECT * FROM users WHERE username='$username' && password='$password'";
$query=mysql_query($sql);
$row=mysql_fetch_assoc($query);
$totalRow=mysql_num_rows($query);
// If username is correct
if ($username = $row['username']) {
// If password is correct
if ($password = $row['password']) {
?>
<?php
session_register('user_id');
// store session data
$_SESSION['username'];
//retrieve session data
echo "Welcome". $_SESSION['username'];
?>

<?php
} else {
echo "Password is Incorrect! <a href='index.php'>Try Again</a>";
if (session_is_registered('username'){
session_unregister('username');
}
}
} else {
echo "Wrong Password or the User does not exist! <a href='index.php'>Try Again</a>";
if (session_is_registered('username'){
session_unregister('username');
}
}
mysql_free_result($query);
?>

 

Cuase you get a:

Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\newsite\member.php on line 35

Link to comment
https://forums.phpfreaks.com/topic/71755-solved-sessions/#findComment-361375
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.