phantomlimb Posted November 12, 2009 Share Posted November 12, 2009 Hi, I have recently moved hosts. My new host has register globals turned off, while my previous one had register globals on. This code used to work, i could pass the variable $ptag between two pages. But i would like to rewrite it to be compatible with register globals off. This is the first time i have come across this problem, and i've done some searching but am unable to ascertain which part of the code is causing the problem. Any ideas on how i could rewrite this block of code to resolve this issue? <?php session_start(); if ( !session_is_registered( 'ptag' ) ) { session_register( 'ptag' ); } //if ptag value has been set via form method post if (isset($_POST['ptag'])) { $ptag = implode(',', $_POST['ptag']); } //if reset value has been set via form method post set ptag to blank if (isset($_POST['reset'])) { $ptag = ""; } ?> Link to comment https://forums.phpfreaks.com/topic/181237-solved-session-variables-with-register-globals-turned-off/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 12, 2009 Share Posted November 12, 2009 All references to $ptag must be changed to use $_SESSION['ptag'] and any use of session_is_registered() or session_register() must be corrected (depends on how they are being used.) In general session_is_registered('ptag') would become isset($_SESSION['ptag']) and session_register('ptag') would become $_SESSION['ptag'] = $ptag; However, for the code you posted, the first if(){} statement is not needed ($_SESSION variables ARE already part of the session and don't specifically need to be 'registered') and the code would become - <?php session_start(); //if ptag value has been set via form method post if (isset($_POST['ptag'])) { $_SESSION['ptag'] = implode(',', $_POST['ptag']); } //if reset value has been set via form method post set ptag to blank if (isset($_POST['reset'])) { $_SESSION['ptag'] = ""; } ?> Link to comment https://forums.phpfreaks.com/topic/181237-solved-session-variables-with-register-globals-turned-off/#findComment-956099 Share on other sites More sharing options...
phantomlimb Posted November 12, 2009 Author Share Posted November 12, 2009 Perfect. Problem solved. Thank you very much. Link to comment https://forums.phpfreaks.com/topic/181237-solved-session-variables-with-register-globals-turned-off/#findComment-956441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.