Jump to content

Help with header command


Darkmatter5

Recommended Posts

I have a site that utilizes member login and sessions.  If the session isn't set the page redirects the user to a unregistered/restricted access version of the site.  Now I'm wanting to use the following code to detect the users screen resolution and use a specific css depending on the users resolution.

 

Here's the code I wish to implement.

<?php
    $url=$_SERVER['PHP_SELF'];
    
    if(isset($HTTP_COOKIE_VARS["resolution"])) {
        $resolution = $HTTP_COOKIE_VARS["resolution"];
    }
    else{
?>
<script language="javascript">
<!–-
go();
        
function go() {
    var today=new Date();
    var the_date=new Date("August 31, 2020");
    var the_cookie_date=the_date.toGMTString();
    var the_cookie="resolution="+ screen.width +"x"+ screen.height;
    var the_cookie=the_cookie + ";expires=" + the_cookie_date;
    document.cookie=the_cookie
    location='<?php echo "$url"; ?>'; //refresh the page with the resolution set
}
//–>
</script>
<?php
    }
?>

 

Now here's my current user restricted page.

<?php
require('library/config.inc.php');
require('library/ecabinet_funcs.php');
$ec = new ecabinet();
$page_title = "E-Cabinet Main Page";

//Start output buffering:
ob_start();

//Initialize a session:
session_start();

//If no member_id session variable exists, redirect the user:
if(!isset($_SESSION['member_id'])) {
	$url = "index.php";
	ob_end_clean();
	header("Location: $url");
	exit();
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $page_title; ?></title>
<link href="library/config.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="main">
  <div id="banner"><table width="100%" height="100%" border="0" align="center">
      <tr>
        <td width="50%" valign="bottom"><?php $ec->bannertext(); ?></td>
        <td align="right" valign="bottom"><?php echo date("F j, Y, h:i:s A"); ?></td>
      </tr>
    </table>
  </div>
  <div id="content">
    <div id="c_main">
      <div id="cm_menu">
        <table width="100%">
          <tr>
            <td><?php $ec->user_rights(index); ?></td>
            <td align="right"><?php $ec->version(); ?></td>
          </tr>
        </table>
      </div>
      <div id="cm_content"></div>
      <div id="cm_footer">
        Copyright &copy 2008 by ??.  All rights reserved.
      </div>
    </div>
    <div id="c_tools">
      <div id="ct_login">
        <div align="center"><?php $ec->login_tool(); ?></div>
      </div>
      <div id="ct_title"></div>
    </div>
  </div>
</div>
</body>
</html>

<?php
ob_end_flush();
?>

 

As you can see the resolution dtetection code looks to see if the resolution cookie variable exists, if it doesn't it creates it and reloads the page so the cookie can be detected, but this reloading conflicts with my registered/unregistered user redirection code.  What can I do to have both?

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.