essjay_d12 Posted May 17, 2007 Share Posted May 17, 2007 I want to send a php variable (the current URL) to a new .php file without doing it through a form/hidden field - but i need a button - so i though I could do it somehow with 'onClick'? Is this possible and how? cheers d Quote Link to comment https://forums.phpfreaks.com/topic/51806-sending-a-value-with-onclick/ Share on other sites More sharing options...
MadTechie Posted May 17, 2007 Share Posted May 17, 2007 cookie or sessions would work Quote Link to comment https://forums.phpfreaks.com/topic/51806-sending-a-value-with-onclick/#findComment-255243 Share on other sites More sharing options...
vbnullchar Posted May 17, 2007 Share Posted May 17, 2007 you should have an idea <?php if(!$c_employee->isLogged()) { /* encrypt query string */ $url=base64_encode($config['site_root'].'?'.$_SERVER['QUERY_STRING']); header("Location: index.php?url=".$url); exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51806-sending-a-value-with-onclick/#findComment-255258 Share on other sites More sharing options...
taith Posted May 17, 2007 Share Posted May 17, 2007 or just send it via get... <a href="location.php?variable=string">text</a> then echo $_GET[variable]; Quote Link to comment https://forums.phpfreaks.com/topic/51806-sending-a-value-with-onclick/#findComment-255259 Share on other sites More sharing options...
MadTechie Posted May 17, 2007 Share Posted May 17, 2007 all true i thought he wanted it visible to the page.. should of read twice! lol Quote Link to comment https://forums.phpfreaks.com/topic/51806-sending-a-value-with-onclick/#findComment-255262 Share on other sites More sharing options...
essjay_d12 Posted May 17, 2007 Author Share Posted May 17, 2007 I am now trying to do it with sessions - the page I am sending it to is a pop up window yet it doesnt seem to echo out the session when I know it has set correctly in the previous page. here is my code first page session_start; function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } $_SESSION['URL'] = curPageURL(); echo $_SESSION['URL']; echo "<input type=\"button\" name=\"web_data\" value=\"Web Page ...\" ". "onclick=\"return window.open('http://localhost/page2.php', 'web_data', 'menubar=1,location=1,directories=1,toolbar=1,scrollbars,resizable,width=800,height=600');\" />\n"; the Correct URL and button appears Page 2 session_start; echo $_SESSION['URL']; echo " Hello"; But only hello appears!!! Anybody explain? cheers d Quote Link to comment https://forums.phpfreaks.com/topic/51806-sending-a-value-with-onclick/#findComment-255326 Share on other sites More sharing options...
MadTechie Posted May 17, 2007 Share Posted May 17, 2007 try <?php session_start(); ?> instead of <?php session_start; ?> Quote Link to comment https://forums.phpfreaks.com/topic/51806-sending-a-value-with-onclick/#findComment-255487 Share on other sites More sharing options...
essjay_d12 Posted May 17, 2007 Author Share Posted May 17, 2007 still doesnt display it Quote Link to comment https://forums.phpfreaks.com/topic/51806-sending-a-value-with-onclick/#findComment-255511 Share on other sites More sharing options...
essjay_d12 Posted May 17, 2007 Author Share Posted May 17, 2007 There are many other pages conflicting with this file, which may be doing a session_destroy - i cant view them to find out, is there another way (instead of sessions) how would I do the same thing using the function but possibly with cookies etc or any other ways? Quote Link to comment https://forums.phpfreaks.com/topic/51806-sending-a-value-with-onclick/#findComment-255535 Share on other sites More sharing options...
taith Posted May 17, 2007 Share Posted May 17, 2007 4 ways of transfering data page to page... get, post, sessions, cookies... if sessions are scratched, the next one that you prolly want to use for that is either get(use once(ish)), or cookies(use many times)... Quote Link to comment https://forums.phpfreaks.com/topic/51806-sending-a-value-with-onclick/#findComment-255572 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.