Jump to content

jtorral

Members
  • Posts

    26
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

jtorral's Achievements

Member

Member (2/5)

0

Reputation

  1. The problem is as follow. 1. This is some old code thats been around for ages. 2. Mobile devices have different screen sizes. 3. Setting the session of the screen size lets me manipulate the various page width and image sizes to display on a mobile device based on the width. If a device has a screen width of x I want to make sure the image is set for that screen width. with different device screens, the image can be too big or small. 4. Setting the session also let me access that stores screen size of other functions on the page like resizing pop up boxes and so on. Hope that explains it
  2. thanks, will try index.php for ajax request.
  3. I have this simple line of code which somewhat works. Until I try to do math against the $screenWidth $screenWidth = '<script> document.write(screen.width); </script>'; If I echo $screenWidth I see 3072 which is what I expect. But if I do something like $nw = $screenWidth - 20; I get a php error about an Unsupported operand type string - int I tried casting $screenWidth = intval($screenWidth) but I always get 0. So I do some more debugging with this little bit of code echo "<pre>"; print_r(str_split($screenWidth)); echo "</pre>"; echo "<br>"; if( is_numeric($screenWidth) ) { echo "Numeric $screenWidth</br>"; } else { echo "String $screenWidth</br>"; } And here is what I get Array ( [0] => < [1] => s [2] => c [3] => r [4] => i [5] => p [6] => t [7] => > [8] => [9] => d [10] => o [11] => c [12] => u [13] => m [14] => e [15] => n [16] => t [17] => . [18] => w [19] => r [20] => i [21] => t [22] => e [23] => ( [24] => s [25] => c [26] => r [27] => e [28] => e [29] => n [30] => . [31] => w [32] => i [33] => d [34] => t [35] => h [36] => ) [37] => ; [38] => [39] => < [40] => / [41] => s [42] => c [43] => r [44] => i [45] => p [46] => t [47] => > ) String 3072 And var_dump($screenWidth) shows string(48) "3072" I cant tried the ajax method but setting a session is not working as expected. In reality the one line of code is really simple if only I can get the actual numeric value to manipulate in my code. Any thoughts? Thanks
  4. I managed to get a little further with these mods. But there is still an issue. <?php // $SID is set in indet.php session_start() if (session_id() != '') { session_write_close(); } session_id($SID); session_start(); if( isset($_REQUEST['sw'] ) ) { $screenWidth = $_REQUEST['sw']; $_SESSION['gs_session_screen_width'] = $screenWidth; return; } I am capturing the session id from the first session start on index.php and setting that into the variable SID then I close the session in the handler for the ajax call as you can see above. This has gotten me a lot further. But I cannot see the session until I refresh the page. In the index file I have this <?php ini_set('display_errors', 1); error_reporting(E_ALL); session_start(); //header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1 //header("Pragma: no-cache"); // HTTP 1.0 //header("Expires: 0"); // Proxies $SID = session_id(); include_once( '../gallerysoftconfig.php'); include_once( 'functions.php'); include_once( '../iconfig.php'); require_once 'indexPreChecks.php'; require_once 'sessionChecks.php'; require_once 'screenDetect.php'; echo "<pre>"; print_r($_SESSION); echo "</pre>"; You can see where SID is set, then the call to screenDetect.php Then I display sessions I dont see the session I refresh the page the session shows up now. I need it to be set and be visible first time around. I tried some cache settings but they didnt work. I left them in the code with comments
  5. Don't know if I should post this here or in the jquery forum. But here is the deal. My index.php has the following .... <?php session_start( [ 'cookie_lifetime' => 86400, ]); //session_start(); //$SID = session_id(); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); include_once( '../gallerysoftconfig.php'); include_once( 'functions.php'); include_once( '../iconfig.php'); include_once( 'indexPreChecks.php'); include_once( 'sessionChecks.php'); include_once( 'screenDetect.php'); //print_r($_SESSION); //$xyz = $_SESSION['gs_session_screen_width']; //echo "Width: $xyz <br>"; As you can see lots commented out for testing Then the issue is in screenDetect.php And here is screenDetect.php <?php if( isset($_REQUEST['sw'] ) ) { $screenWidth = $_REQUEST['sw']; $_SESSION['gs_session_screen_width'] = $screenWidth; //$s = $_SESSION['gs_session_screen_width']; //echo "New session processed: $s"; return; } if(isset($_SESSION['gs_session_screen_width']) ) { $screenWidth = $_SESSION['gs_session_screen_width']; //echo "Session processed: $screenWidth"; return; } if(! isset($_SESSION['gs_session_screen_width']) ) { echo ' <script src="https://apis.google.com/js/platform.js" async defer></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script> <script type="text/javascript"> var screenWidth = screen.width; $.ajax({ type: "POST", url: "/screenDetect.php", data: {sw: screenWidth}, success: function() { } }); </script> '; } ?> There are some comments there that I use for validation But the story is, that the ajax call is simply getting the device screen size and calling it self with a POST. That works just fine The if( isse($_REQUEST['sw']) ) does get executed and sets the session. I have validated this by assigning the session to a variable and it does print it. I even do a print_r($_SESSION) and I see it. However, when I pickup the code in index.php, the session that was set there is no longer visible. Its like it never existed. I have tried the session_start() at the begining of screenDetect but no luck. Any idea what is going on ??? Thanks JT
×
×
  • 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.