Jump to content

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

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.