Kurrel Posted August 22, 2007 Share Posted August 22, 2007 Hey Freaks, I have created a .php file that creates a line graph. With variables declared inside that file, it draws the graph but I now need to pass data to it. After an earlier post $_SESSION seemed the way to go, but it doesn't appear to be visible inside that .php file. I use the file thus : print("<pre style='font-family:verdana;font-size:13'>"); print_r($_SESSION); print("</pre>"); print("<img src='".BASE."/basefunctions/maxgraphs/linegraphdrawer.php' alt='test'>"); and inside the function foreach ($_SESSION as $sesskey=>$sessval) { imagettftext($im, $linefontsize, 0, 200, 50, $black, $font, "TEST ".$sessval); } which breaks the file because, as far as I can tell, $_SESSION is empty. :-\ As far as I was aware, $_SESSION is variable to all functions called throughout the process... or is the <img> reference bypassing that? If so, how do I make the variable available inside the file? Kurrel. Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/ Share on other sites More sharing options...
pranav_kavi Posted August 22, 2007 Share Posted August 22, 2007 ve u added session_start() at d start of the php file....? i think that is mandatory whenever ur modifyin or adding or accessin the session array. Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/#findComment-330724 Share on other sites More sharing options...
Kurrel Posted August 22, 2007 Author Share Posted August 22, 2007 I have the session_start() in the original file, index.php. Just in case, I've just added it to the linegraphdrawer.php. It declared a new session, rather than plugging the existing one. Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/#findComment-330737 Share on other sites More sharing options...
pranav_kavi Posted August 22, 2007 Share Posted August 22, 2007 ru including linegraphdrawer.php in index.php? in tat case..u need to mention session_start() only at d start of index.php. Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/#findComment-330746 Share on other sites More sharing options...
Kurrel Posted August 22, 2007 Author Share Posted August 22, 2007 If I include linegraphdrawer.php in index.php the drawer bombs as the headers are redeclared. The only way I was able to get GD to work was this fashion, and now it seems that it's functionality is compromised by an inability to pass data... Seems a database reference may just be the only way to go, unless there's yet another way to reference the session? Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/#findComment-330751 Share on other sites More sharing options...
pranav_kavi Posted August 22, 2007 Share Posted August 22, 2007 Once the session variable is set,it can be accessed in any page of the application.pls post the code wher u set the session. Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/#findComment-330756 Share on other sites More sharing options...
Kurrel Posted August 22, 2007 Author Share Posted August 22, 2007 <?PHP // Preperation { session_start(); ob_start(); First thing in index.php, $_SESSION["data"] = "TEST"; print("<pre style='font-family:verdana;font-size:13'>"); print_r($_SESSION); print("</pre>"); print("<img src='".BASE."/basefunctions/maxgraphs/linegraphdrawer.php?test=12' alt='test'>"); Is then run, and the pre details the session fully, but the image that is presented on the next line does not have session referenced inside it. Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/#findComment-330759 Share on other sites More sharing options...
pranav_kavi Posted August 22, 2007 Share Posted August 22, 2007 let me get tis clear... print_r($_SESSION); the above line prints the session value ? and the session value cannot be accessed in linegraphdrawer.php ? Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/#findComment-330769 Share on other sites More sharing options...
Kurrel Posted August 22, 2007 Author Share Posted August 22, 2007 Absolutely. the print("<pre style='font-family:verdana;font-size:13'>"); print_r($_SESSION); print("</pre>"); displays every value contained in the session, but they are not available inside linegraphdrawer.php. Hence, my confusion. Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/#findComment-330770 Share on other sites More sharing options...
pranav_kavi Posted August 22, 2007 Share Posted August 22, 2007 will this work... print("<img src='".BASE."/basefunctions/maxgraphs/linegraphdrawer.php?test=12' alt='test'>"); wat does linegraphdrawer.php return?Have u tried executing d code widout using session variables in linegraphdrawer.php? mean just 2 check if an image is actually being returned frm linegraphdrawer.php and displayed on index.php. Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/#findComment-330797 Share on other sites More sharing options...
Kurrel Posted August 22, 2007 Author Share Posted August 22, 2007 It all works at the moment, I have hard coded values inside linegraphdrawer.php that I am using to render the image. It works, and displays the graph using the hard data, but I need to replace that hard data with a variable data set stored in the session. the ?test=12 inside the <img> tag was to check whether _GET worked... it does, the _GET is visible when passed this way. Still no session, though. With or without the session, the .php renders the image... unless I include linegraphdrawer.php in index.php. I can then see the session, but am unable to utilize gd to draw the graph, the purpose for which it was created in the first place. Blowing my mind. Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/#findComment-330807 Share on other sites More sharing options...
pranav_kavi Posted August 22, 2007 Share Posted August 22, 2007 I assume the image is being displayed way bfore the session is set..though dont know how. One solution is to pass the session array as a request parameter to the url at src. Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/#findComment-330815 Share on other sites More sharing options...
Kurrel Posted August 22, 2007 Author Share Posted August 22, 2007 Nope, the session is the first thing set in the whole process. The image is drawn when the <img> flag is referenced, without prior work. The session exists before and after, but I begin to think that since it's referencing linegraphdrawer.php directly it is using it as an external resource, in which the current variables of index.php are not visible. Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/#findComment-330817 Share on other sites More sharing options...
Kurrel Posted August 22, 2007 Author Share Posted August 22, 2007 I have tried to circumvent the problem by putting the variables into a database, only to find that any sql work apparently also breaks gd. What use is a graphic set if it can't be used for anything but 100% static, isolated instances? Is there ANY way (besides _GETting through the URL) to get variables into this?! Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/#findComment-330844 Share on other sites More sharing options...
pranav_kavi Posted August 22, 2007 Share Posted August 22, 2007 One solution is to pass the session array as a request parameter to the url at src. did u try tis?I undrstand its not a preferred solution... Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/#findComment-330847 Share on other sites More sharing options...
Kurrel Posted August 22, 2007 Author Share Posted August 22, 2007 If by this you mean print("<img src='".BASE."/basefunctions/maxgraphs/linegraphdrawer.php?a=".$_SESSION["blah"]."' alt='test'>"); I can only extend it so far... if I'm drawing a graph comparing 6 data sets across a year thats 72 variables before I've even passed the actual graph details. The string length passable in the URL becomes a problem. Quote Link to comment https://forums.phpfreaks.com/topic/66121-_session-visibility-to-php-file/#findComment-330856 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.