Jump to content

Session transfer


k3n3t1k

Recommended Posts

I already have the session start on the page. It still wont transfer.

 

Here is the code, maybe this will help:

<?php

require_once "dbconfig.php";

$sql = mysql_query("SELECT * FROM studentcenter WHERE username='".addslashes($_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'] == sha1($_POST['password'])) {
/* Checks if passwords match */

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

?> 

Link to comment
https://forums.phpfreaks.com/topic/77043-session-transfer/#findComment-390195
Share on other sites

Sure, here is login.php:

 

<?php
session_start();
require_once "dbconfig.php";

$sql = mysql_query("SELECT * FROM studentcenter WHERE username='".addslashes($_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'] == sha1($_POST['password'])) {
/* Checks if passwords match */

/* Start Session */
header ("Cache-control: private");
$_SESSION['sessionname'] = $_POST['username'];
echo("Welcome, Forwarding");
header("location: studenthome.php");
}else{
echo "Incorrect Login, please try again or <a href="register.php">Register</a>"
}

?> 

 

 

and here is studenthome.php:

 

<html>

<head>
<title>Gibson Partners -- Student Center</title>
<link rel="stylesheet" type="text/css"
href="css.css" />
</head>
<body>

<div id="top">
<?php include("leftnav.php"); ?>	

<div id="main">

<table width="90%"><tr><td>
Hello

<?php
session_start();

if(!isset($SESSION["sessionname"])){
echo "You must be ogged in to do this!";
}else{
echo "Welcome ".$SESSION["sessionname"];
echo "YAY IT WORKED!!!";

echo "<a href="logout.php">Logout</a>";

}
?>


</td></tr></table>

<div id="right">
<?php include("right_border.php"); ?>


</div>
</div>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/77043-session-transfer/#findComment-390221
Share on other sites

theres the problem... session_start()

has to be put at the top.. or BEFORE anything gets output to the browser meaning...

there can NOT be ANY html or blank lines before the session_start.

also its supposed to be $_SESSION not $SESSION.. see the difference?

 

soo.....

<? session_start(); ?>
<html>
<head>
<title>Gibson Partners -- Student Center</title>
<link rel="stylesheet" type="text/css"
href="css.css" />
</head>
<body>

<div id="top">
<?php include("leftnav.php"); ?>	

<div id="main">

<table width="90%"><tr><td>
Hello

<?php

if(!isset($_SESSION["sessionname"])){
echo "You must be ogged in to do this!";
}else{
echo "Welcome ".$_SESSION["sessionname"];
echo "YAY IT WORKED!!!";

echo "<a href="logout.php">Logout</a>";

}
?>


</td></tr></table>

<div id="right">
<?php include("right_border.php"); ?>


</div>
</div>
</div>
</body>
</html>

 

try that and see if that works for you

Link to comment
https://forums.phpfreaks.com/topic/77043-session-transfer/#findComment-390228
Share on other sites

that code works for me... try making some very basic pages... (no login script).

 

page1

<?
      session_start();
      $_SESSION['username'] = "MyName";

      echo "Hello! ". $_SESSION['username']."<br />";
?>
<a href="page2.php">Click here to continue</a>

 

page2

<?
     session_start();
     echo "Hello ". $_SESSION['username'].
     echo "You made it to page 2";
?>

 

that code SHOULD work. if it doesnt... then there is a problem with your server/php/apache...something.

if it does work.. then we know its one of the other pages.. something typed wrong.

 

try on studenthome.php putting in at the bottom

print_r($_SESSION);

 

see what happens

Link to comment
https://forums.phpfreaks.com/topic/77043-session-transfer/#findComment-390246
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.