0

here is the ordeal:

on index.php

<?php
    session_start();
    $url = $_SERVER['HTTP_REFERER'];
    $_SESSION['abc'] ='$url';
?>

i echo on the page $_SERVER['HTTP_REFERER']; and i get what i want

later on site i have a reservation page and i use the session to

<?php 
    session_start();

    if (isset($_SESSION['abc'])) {
        echo $_SESSION['abc'];
    } 
    else {
        echo 'error';
    }               
?>

it echo's error and i'm confused why the data isn't passing..

Any idea's from the php gurus out there, thanks. Just want it to print the HTTP_REFERER

9
  • is session_start() called on all of the pages? cause you say.."later" on site. Commented May 30, 2012 at 23:37
  • 2
    Try to print_r($_SESSION) in the second page. And in index.html, replace $_SESSION['abc'] = '$url' with $_SESSION['abc'] = $url. Commented May 30, 2012 at 23:39
  • @bsdnoobz: Why put quotes around $url at all? Quotes are not needed. Commented May 30, 2012 at 23:40
  • do I have to call session_start() on every single page? or just on pages I want to use $_SESSION superglobal Commented May 30, 2012 at 23:42
  • You need to call session_start() on every page that you would like to access session data. Once you have started the session, session_start() only resumes the previously started session. Commented May 30, 2012 at 23:50

2 Answers 2

0

Looking at the comments, you appear to be using both HTTP and HTTPS.

You will need to pass a session ID from HTTP to HTTPS.

index.php

<?php
    session_start();

    $_SESSION['abc'] = $_SERVER['HTTP_REFERER'];

    $session_id = session_id();
?>

You will then need to pass $session_id to your reservation page, perhaps via GET:

reservation.php

<?php
    session_start();

    session_id($_GET['session_id']);

    if (isset($_SESSION['abc']))
        echo $_SESSION['abc'];
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! My only issue now is that i'm getting the referer as the page before my reservation page, not the initial HTTP_REFERER, so it echo's "mysite.com/pagebeforereservation" how do i get the initail HTTP_REFERER to transfer over?
0

Unfortunately, by default a session won't persist between HTTP and HTTPS. Rather than rehash the solutions, I'll point towards where the question has come up before:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.