Jump to content


Photo

Alternative Way to Call a Variable


  • Please log in to reply
5 replies to this topic

#1 gladiator83x

gladiator83x
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 24 July 2006 - 05:58 PM

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'];


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 24 July 2006 - 06:15 PM

You can use sessions:

file 1:
<?php
session_start(); // must be called at the start of each script where you use sessions.
$_SESSION['string11'] = $hlink;
?>

file 2:
<?php
session_start();
$title = $_SESSION['string11'];
?>

Ken

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 24 July 2006 - 06:29 PM

Or a cookie, works basically the same as a session.

#4 gladiator83x

gladiator83x
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 24 July 2006 - 07:42 PM

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 21



Warning: 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 21

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 21


#5 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 24 July 2006 - 08:08 PM

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.
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 July 2006 - 09:40 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users