1

I hosted my website on Godaddy. I encountered by the past the problem of retrieving my session after a php redirection by using exit() as following:

<?php
$_SESSION['mysession']='session_name';
header('Location: http://www.mywebsite.com/?blabla=blubb');
exit();

Ant it works great but when I export my code on Godaddy server, it doesn't work out there, I can't retrieve my session anymore, and I don't know why. Please help me.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
kabrice
  • 1,475
  • 6
  • 27
  • 51
  • Do you have a `session_start();` before you're trying to set or get the session? If you don't, you might have `session.auto_start` enabled on the previous server while it's disabled on GoDaddy's server. (Disabled is the default) – M. Eriksson Jul 03 '16 at 08:42
  • Yes I do have session_start() – kabrice Jul 03 '16 at 08:56
  • 3
    This actually looks like a duplicate: http://stackoverflow.com/questions/17242346/php-session-lost-after-redirect (there are many Q/A here on SO about the same thing, you should check them out). – M. Eriksson Jul 03 '16 at 09:05
  • Indeed, duplicate of http://stackoverflow.com/q/17242346 – PaulH Jul 03 '16 at 09:12

1 Answers1

0

The statement session_start(); should be included at the beginning of the php page.

If you have html code in your page, Then it should be look like this:

<?php
// Start the session
session_start();

$_SESSION['mysession']='session_name';
header('Location: http://www.mywebsite.com/?blabla=blubb');
exit();
?>
<!DOCTYPE html>
<html>
<body>
Aseem PM
  • 97
  • 6
  • Sorry, it doesn't work, I got this error "A session had already been started - ignoring session_start() in /Applications/XAMPP/xamppfiles/htdocs/..." – kabrice Jul 04 '16 at 00:47
  • `` Just try this.! – Aseem PM Jul 05 '16 at 12:22
  • @EdgarKAMDEM if you get someone to solve something for you, then mark it answered with the green check mark. See http://meta.stackexchange.com/a/5235 . You also have the rep to upvote posts (the up arrow). I am trying to answer a mysql question for you, but you have no history of doing what I just said – Drew Sep 17 '16 at 01:25