Quantcast
Channel: Active questions tagged header - Stack Overflow
Viewing all articles
Browse latest Browse all 699

Including a header redirect resets $_SESSION variables? Echoing without redir works

$
0
0

was racking my brain for the last 2 days wondering why my code didnt work. basically tested and removed blocks till I realised that ONLY if i remove the header and return lines in my fn, the $_SESSION['errormsg'] sets and can be echoed later. So my question is why does the header redirect make it not work when i later call for echo $_SESSION['errormsg']? thanks! sorry am quite new still!

function accountCreate($username) {    if(( strlen($username) < 1 )) {        $_SESSION['errormsg'] = 'Please fill out all fields.';        header ('location: accountcreate.php');        return;    }}

main index.php:

<?phprequire_once "pdo.php";require_once "php-accounthandling.php";require_once "php-formhandling.php";require_once "php-messagedisplay.php";session_start();//redir if logged in (dlted to test)//validate and insert form dataif (isset($_POST['create'])) {    accountCreate($_POST['username']);}?><!DOCTYPE html>...<?php displayMessage(); ?>

Tried asking chatGPT, tried a couple discord groups, still don't understand. One answer said that I should check my error_log in case i am outputting before the header, but doubt this it the case, and my error_log is clean.


Viewing all articles
Browse latest Browse all 699

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>