gladiator83x Posted July 24, 2006 Share Posted July 24, 2006 Hi All,Is there anyway that I can pass a variable to another file besides using a hyperlink or some sort of form? This is the way that I have been doing it below: (string 11 is what was passed)file 1:echo '<form method="post" action=" confirm.php?string11=' . $hlink . ' "><br><br><br /><input type="submit" name="submit" value="Review Closure" /></form>';echo '</CENTER>';file 2:$title=$_GET['string11']; Quote Link to comment https://forums.phpfreaks.com/topic/15520-alternative-way-to-call-a-variable/ Share on other sites More sharing options...
kenrbnsn Posted July 24, 2006 Share Posted July 24, 2006 You can use sessions:file 1:[code]<?phpsession_start(); // must be called at the start of each script where you use sessions.$_SESSION['string11'] = $hlink;?>[/code]file 2:[code]<?phpsession_start();$title = $_SESSION['string11'];?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/15520-alternative-way-to-call-a-variable/#findComment-63032 Share on other sites More sharing options...
wildteen88 Posted July 24, 2006 Share Posted July 24, 2006 Or a cookie, works basically the same as a session. Quote Link to comment https://forums.phpfreaks.com/topic/15520-alternative-way-to-call-a-variable/#findComment-63043 Share on other sites More sharing options...
gladiator83x Posted July 24, 2006 Author Share Posted July 24, 2006 I tried using the session start function and I received these errors. I received this error when I put the session_start in the middle of the file; when I put it at the beginning of the file and try to echo out the variable that was passed, I received nothing. Anyone know what I am doing wrong?Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /export/home2/webpages/more_metrics.php:6) in /export/home2/webpages/more_metrics.php on line 21Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /export/home2/webpages/more_metrics.php:6) in /export/home2/webpages/more_metrics.php on line 21Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /export/home2/webpages/more_metrics.php:6) in /export/home2/webpages/more_metrics.php on line 21 Quote Link to comment https://forums.phpfreaks.com/topic/15520-alternative-way-to-call-a-variable/#findComment-63096 Share on other sites More sharing options...
ryanlwh Posted July 24, 2006 Share Posted July 24, 2006 you have to include session_start to the file passing the variable AND the file receiving the variable. and you can only use this function BEFORE any output(or some headers) are sent to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/15520-alternative-way-to-call-a-variable/#findComment-63117 Share on other sites More sharing options...
wildteen88 Posted July 25, 2006 Share Posted July 25, 2006 You have ouput at line 6 in more_metrics.php. Whats is at lines 4 - 8? If its output text/html/whitespace you cannot use session_start after the output. Make sure session_start(); is the first line of code for any page that needs session. Quote Link to comment https://forums.phpfreaks.com/topic/15520-alternative-way-to-call-a-variable/#findComment-63299 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.