GET/ POST alternative?

Status
Not open for further replies.

Jondoe0069

New member
Mar 21, 2007
1,317
19
0
Estados Unidos
I have a multiple page landing page with all internal links and I want to be able to pass the Keyword data with the user to any page he visits on my site. That way, I can eventually append it to the sub ID when he clicks the affiliate link.

So far, I've created variables to gather all the keyword data from the URL. I could hand code every link ti append the data from the variables- but is there some universal way to just send hidden post data with the user no matter what link he clicks on?

I would rather not get into cookies- unless it's not too difficult.

Any help is appreciated. Thanks!
 


You can use session cookies, very easy.

<?php
session_start(); // have this high up in all your php pages, need to be run before the code below

$_SESSION['blabla'] = 'something';
?>

This is then set on all pages the user visits as long as he has his browser open.
 
Does this look right for storing my variables?

Code:
 <?php

$YSMRAW = $_GET["YSMRAW"];
$YSMKEY = $_GET["YSMKEY"];
$YSMDID = $_GET["YSMDID"];
$keyword= $_GET["KEYWORD"];

if (isset($YSMDID))
{
session_start();

$_SESSION['YSMRAW'] = $YSMRAW;
$_SESSION['YSMKEY'] = $YSMKEY;
$_SESSION['YSMDID'] = $YSMDID;
}
elseif (isset($keyword))
{
session_start();

$_SESSION['keyword'] = $keyword;
}
endif;

?>

Also, do you need to include session_start(); on pages that just need to maintain the data in the cookie and don't actually set or retrieve variables?
 
This is what I got now-

Code:
<?php

$YSMRAW = $_GET["YSMRAW"];
$YSMKEY = $_GET["YSMKEY"];
$YSMDID = $_GET["YSMDID"];
$keyword= $_GET["KEYWORD"];

if (isset($YSMDID))
{
session_start();
$_SESSION['YSMRAW'] = $YSMRAW;
$_SESSION['YSMKEY'] = $YSMKEY;
$_SESSION['YSMDID'] = $YSMDID;
}
elseif (isset($keyword))
{
session_start();
$_SESSION['keyword'] = $keyword;
}
else
{
session_start();
}

?>

I'm getting an error saying that the session started and could not be started (for the else statements)... but it shouldn't have started unless the variables above weren't set.

Is something wrong with the way I used isset?
 
Maybe it was already started earler in your code. It has to be run only once. I'd do the code like this.
<?php
session_start();
$YSMRAW = $_GET["YSMRAW"];
$YSMKEY = $_GET["YSMKEY"];
$YSMDID = $_GET["YSMDID"];
$keyword= $_GET["KEYWORD"];

if (isset($YSMDID)){
$_SESSION['YSMRAW'] = $YSMRAW;
$_SESSION['YSMKEY'] = $YSMKEY;
$_SESSION['YSMDID'] = $YSMDID;
}
elseif (isset($keyword)){
$_SESSION['keyword'] = $keyword;
}


?>
 
  • Like
Reactions: Jondoe0069
When I run the page now, it gives me the following errors:

Code:
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/content/j/o/n/jondoe0069/html/offer/index.php:2) in /home/content/j/o/n/jondoe0069/html/offer/index.php on line 9

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/content/j/o/n/jondoe0069/html/offer/index.php:2) in

I've tried the following code:

Code:
<?php
session_start();

$YSMRAW = $_GET["YSMRAW"];
$YSMKEY = $_GET["YSMKEY"];
$YSMDID = $_GET["YSMDID"];
$KEYWORD= $_GET["KEYWORD"];

if (isset($YSMDID))
{
$_SESSION['YSMRAW'] = $YSMRAW;
$_SESSION['YSMKEY'] = $YSMKEY;
$_SESSION['YSMDID'] = $YSMDID;
}
elseif (isset($KEYWORD))
{
$_SESSION['KEYWORD'] = $KEYWORD;
}

?>

and

Code:
<?php

$YSMRAW = $_GET["YSMRAW"];
$YSMKEY = $_GET["YSMKEY"];
$YSMDID = $_GET["YSMDID"];
$KEYWORD= $_GET["KEYWORD"];

session_start();

$_SESSION['YSMRAW'] = $YSMRAW;
$_SESSION['YSMKEY'] = $YSMKEY;
$_SESSION['YSMDID'] = $YSMDID;
$_SESSION['KEYWORD'] = $KEYWORD;


?>

Is anyone familiar with this error? I don't think it has anything to do with the code... or maybe it does?

Thanks for your help!
 
Yes, you have to have session_start(); before anything is sent to the browser!
As I told you should should have it as high up on the page as possible. At the absolute top if possible.
 
Status
Not open for further replies.