Jump to content

Passing variables with window.location


avincent

Recommended Posts

I am trying to pass a session variable from one page to another, but every time I use the following code you are directed to the right page, but it will not display the content of that page. It seems as if the variable is never making it to that next page. Any suggestions.

 

----------------------

index.php:

 

<?php

session_start();

include "db_connect.php";

if(!isset($_POST['submit']))

{

?>

 

//Display the page here

 

<?php }else{

 

  $user = protect($_POST['user_name']);

  $pass = protect($_POST['password']);

 

if($user && $pass)

{

$pass =($pass); //compare the encrypted password

$sql="SELECT user_name,company_name FROM `user` WHERE `user_name`='$user' AND `password`='$pass'";

$query=mysql_query($sql) or die(mysql_error());

 

    if(mysql_num_rows($query) > 0)

    {

      $row = mysql_fetch_assoc($query);

      $_SESSION['user_name'] = $row['user_name'];

      $_SESSION['company_name'] = $row['company_name'];

 

  echo "<script type=\"text/javascript\">window.location=\"client-resources.php\"</script>";

    }

    else

  {

    echo "<script type=\"text/javascript\">

alert(\"Username and password combination is incorrect!\");

window.location=\"index.php\"</script>";

  }

}

else

{

  echo "<script type=\"text/javascript\">

alert(\"You need to gimme a username AND password!\");

window.location=\"index.php\"</script>";

}}?>

 

-----------------------------------------------------------------------------

redirected page code:

 

<?php

session_start();

?>

 

<div id="main-content"> 

<?php

if(isset($_SESSION['user_name']))

{

$user_name = $_SESSION['user_name'];

 

include ("inc/client-resources/client-resources.php");

 

 

}

?>

Link to comment
https://forums.phpfreaks.com/topic/180595-passing-variables-with-windowlocation/
Share on other sites

This is they way the code looks this morning. Still not able to get the variable $_SESSION['user_name'] to pass to the next page.

 

----------------------

index.php:

 

session_start();
   include "db_connect.php";
   if(!isset($_POST['submit']))
   {

 

//Display the page here

 

}else{

  $user = protect($_POST['user_name']);
  $pass = protect($_POST['password']);

if($user && $pass)
{
$pass =($pass); //compare the encrypted password
$sql="SELECT user_name,company_name FROM `user` WHERE `user_name`='$user' AND `password`='$pass'";
$query=mysql_query($sql) or die(mysql_error());

    if(mysql_num_rows($query) > 0)
    {
      $row = mysql_fetch_assoc($query);
      $_SESSION['user_name'] = $row['user_name'];
      $_SESSION['company_name'] = $row['company_name'];
     
     echo "<script type=\"text/javascript\">window.location=\"client-resources.php\"</script>";
    }
    else
   {
    echo "<script type=\"text/javascript\">
   alert(\"Username and password combination is incorrect!\");
   window.location=\"index.php\"</script>";
   }   
}
else
{         
   echo "<script type=\"text/javascript\">
   alert(\"You need to gimme a username AND password!\");
   window.location=\"index.php\"</script>";
}}

 

-----------------------------------------------------------------------------

redirected page code:

 

  
session_start();

 

<div id="main-content"> 

 

if(isset($_SESSION['user_name']))
{
$user_name = $_SESSION['user_name'];

include ("inc/client-resources/client-resources.php");

}else{
   echo "nope";
}

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.