Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sessions and using header("Location")

    I have a script where i set the session variable and then redirect to another page, on the next page the session variable is getting reset and i have no clue why. anyone have an idea, here is the relevent parts of the script:

    PHP Code:
    session_start();
    $ref = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : "http://{$_SERVER['SERVER_NAME']}/";
    $_SESSION['ref'] = $ref;
    header("Location: contest.php"); 
    and then on the next page i have this:
    PHP Code:
    session_start();
    if(isset(
    $_SESSION['ref'])) {
        
    $ref $_SESSION['ref'];
    }
    print_r($_SESSION); 

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,961
    Thanks
    2
    Thanked 305 Times in 297 Posts
    Edit: never mind what I originally wrote here.

    However, check your web server log for errors and/or turn on full php error reporting. This will tell you if any errors are occurring that are preventing the session from working.
    Last edited by CFMaBiSmAd; 08-31-2007 at 04:17 PM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts
    unfortunately the server has display_errors turned off and the people above me won't let me ask the server admin to turn them back on.

    i tried using the thing below but it still shows nothing
    PHP Code:
    ini_set('display_errors','On');
    error_reporting(E_ERROR E_WARNING E_PARSE); 

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,961
    Thanks
    2
    Thanked 305 Times in 297 Posts
    What does your print_r() show?

    The two pieces of code you posted work correctly on my test system, so there is nothing about just those lines of code that are preventing this from working. That would mean something else in your code or on your server is.

    Do you know for a fact that sessions work and it is just the current code that does not work?
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Regular Coder
    Join Date
    Mar 2005
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the sessions work it is just changing the referrer in the session var to something else when i do the header call i'll paste the whole code for you
    p.s this code was not written by me i have to adapt it from an older site to this new script, i know its ugly sorry
    PHP Code:
    <?
    ini_set
    ('display_errors','On');
    error_reporting(E_ERROR E_WARNING E_PARSE);
    $ref = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : "http://{$_SERVER['SERVER_NAME']}/";
    setcookie("ref"$reftime()+3600);
    print_r($_COOKIE);
    include(
    "header_footer.php");
    class 
    LeapYearChecker {

        function 
    isLeapYear($year){
            if((
    $year 400) == 0){    
                return 
    true;        //Is LeapYear
            
    }else if(($year 100) == 0){
                return 
    false;        //Not a LeapYear
            
    }else if(($year 4) == 0){
                return 
    true;        //Is LeapYear
            
    }else{
                return 
    false;        //Not LeapYear
            
    }
        }
    }
    have_header();
    $currentday date('d');
    $currentmonth date('m');
    $currentyear date('Y');

    ?>
    <?
    if(!$_POST["submit"]) { 
    ?>
    <form action="<? echo $_SERVER['SCRIPT_NAME']; ?>" method="post" enctype="multipart/form-data">
    <label for="day">D:</label>
    <input type="text" name="day" value="" size="2" />
    <label for="month">M:</label>
    <input type="text" name="month" value="" size="2" />
    <label for="year">Y:</label>
    <input type="text" name="year" value="" size="4" />
    <input type="submit" name="submit" value="submit" />
    </form>
        <p>Please submit the day, month, and year you were born, to access the UK Rum Site.</p>
    <?
    } else {
    $error_list = array();

    if(
    $_POST["day"] <= "2") {
        if(
    $_POST["day"] !== "" OR $_POST["day"] >= "1") {
        }else{
            
    $error_list[] =  "<p>The day you were born should be entered as 2 numbers</p>";
        }
    }else{
    //all is good
    //echo "<p>day is 2 or less numbers</p>";
    }
    if(
    $_POST["month"] <= "2") {
        if(
    $_POST["day"] !== "" OR $_POST["day"] >= "1"){
        
    //echo "<p>This is fine</p>";
        
    }else{
            
    $error_list[] =  "<p>The month you were born should be entered as 2 numbers</p>";
        }
    } else {
        
    //echo "<p>month is 2 or less numbers</p>";
    }

    if(
    $_POST["year"] <= "4") {
        if(
    $_POST["day"] !== "" OR $_POST["day"] >= "1"){
            
    //echo "<p>This is fine</p>";
        
    }else{
            
    $error_list[] =  "<p>The year you were born should be entered as 4 numbers</p>";
            
    //echo "<p>why is the year not 4 numbers?</p>";
        
    }
    } else {
        
    //echo "<p>the year is 4 characters long, GOOD.</p>";
    }

    if(
    ctype_digit($_POST["day"]) AND ctype_digit($_POST["month"]) AND ctype_digit($_POST["year"])) {
        
    //echo "<p>All numbers, GOOD.</p>";
    } else {
        
    $error_list[] = "<p>Please enter your date of birth in numeric format.</p>";
    }

    ///month day year verification of actual date
    $thirtyone = array(01,1,03,3,05,5,07,7,08,8,10,12);
    //print_r($thirtyone);

    $thirty = array(04,4,06,6,09,9,11);
    //print_r($thirty);

    $leaper = array(02,2);
    //print_r($leaper);

    if (in_array($_POST["month"], $thirtyone) AND $_POST) {
        
    //    echo "<p>".$_POST["month"]." has 31 days</p>";
        
    if($_POST["day"] <= "31"){
        }else{
            
    $error_list[] = "<p>There isn't even that many days in that month.</p>";
        }
    }

    if (
    in_array($_POST["month"], $thirty) AND $_POST) {
        
    //echo "<p>".$_POST["month"]." has 30 days<br />";
        
    if($_POST["day"] <= "30"){
        }else{
            
    $error_list[] = "<p>There isn't even that many days in that month.</p>";
        }
    }

    if (
    in_array($_POST["month"], $leaper) AND $_POST) {

        
    $LYC = new LeapYearChecker();
        
    $LYC->isLeapYear($_POST["year"]) == true $leapwhat="yes" :$leapwhat="no"
        
        if(
    $leapwhat == "yes"){
            
    //echo "<p>".$_POST["month"]." has 29 days";
            
    if($_POST["day"] <= "29"){
            }else{
                
    $error_list[] = "<p>There isn't even that many days in that month.</p>";
            }
        }else{
            
    //echo "<p>".$_POST["month"]." has 28 days";
            
    if($_POST["day"] <= "29"){
            }else{
                
    $error_list[] = "<p>I know it's a leap year, but there isn't even that many days in february, ever.</p>";
            }
        }
    }

    $submit_date $_POST["year"]."-".$_POST["month"]."-".$_POST["day"];

    $current_date $currentyear."-".$currentmonth."-".$currentday;

    $ageinseconds strtotime($current_date) - strtotime($submit_date);

    //divide by seconds in a year to get he exact age
    //1 year = 31 556 926 seconds
    $oneyear "31556926";

    $create_age $ageinseconds $oneyear;
    $agearr explode("."$create_age);

    if(
    $agearr[0] < "21") {

    //////////check against todays date, cause birfday peeps seem to be denied, due to seconds and decimal place mumbo jumbo

        
    if(($_POST["month"] == date(m) || $_POST["month"] == date(n)) AND ($_POST["day"] == date(j) || $_POST["day"] == date(d)) AND ($_POST["year"] == (date(Y) - "21"))) {        
            
    //echo (date(Y) - "21");
            
    $agearr[0] = 21;
        }else{
            
    $error_list[] = "<p>I'm sorry, but you cannot view this website, as you are not 21.</p>\n\n";
        }
    } else {}

    if(
    $_POST["day"] > "31") {

        
    $error_list[] = "<p>There isn't even that many days.</p>\n\n";

    } else { 
    }   

    if(
    $_POST["month"] > "12"){

    $error_list[] = "<p>There isn't even that many months.</p>\n\n";

    }else{
    }

    if(
    date(Y) < $_POST["year"]){

        
    $error_list[] = "<p>I'm sorry, but you haven't even been born yet. How'd you do that?</p>\n\n";

    }else{
    }

    if(
    count($error_list) > 0) {

        for (
    $checkme 0$checkme count($error_list); $checkme++){ 
            echo 
    $error_list[$checkme]; 
        } 

    echo 
    "<p>Did you make a mistake? <a href=\"".$_SERVER["SCRIPT_NAME"]."\">Try again.</a></p>\n\n";

    }else{
    header("Location: contest.php");
    }
    }
    have_footer();
    ?>

  • #6
    Regular Coder
    Join Date
    Mar 2005
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts
    for some reason its not letting me edit that post, just replace the cookie stuff with the session crap from earlier, i was trying it with cookies but same results

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,961
    Thanks
    2
    Thanked 305 Times in 297 Posts
    So, what does the print_r() in the second - contest.php - file show exactly? And posting that code would help as well.

    You can also turn on error reporting in a .htaccess file using the following -
    Code:
    php_value display_errors On
    php_value error_reporting 6143
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •