Jump to content

Session transfer


k3n3t1k

Recommended Posts

I need some help in transferring my session from one page to the next. I know it has to do with the URL, but whenever I try it never fowards me.

 

If anybody has a suggestion that would be great. Also referancing me to some tutorials would be great too!

 

Thanks,

k3n3t1k

Link to comment
Share on other sites

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