Jump to content

header


Go to solution Solved by fesan,

Recommended Posts

Hi...

 

Updating a small site of mine.

I had a header that read header("location: full-web-page-url"). I replaced this code so it is a bit easier to update my pages in the future.

 

I then added this code:

 

 

host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'index.php';

 

The page has worked flawless before i did this and now i have a "refresh delay". The first page is a form that a user submits. This takes the user to a new page with the execute code(no visuals for user). after execution the page runs this code(se below) to take them back with info about the execution.

 

_SESSION["message"] = "Eventinfoen er endret.";
header("Location: http://$host$uri/$extra"); 

 

The header works fine and the code executes fine, but the session message is not echoed on the next page before i press refresh in my browser.

In the php manual i find this: 

Session ID is not passed with Location header even if session.use_trans_sid is enabled. It must by passed manually using SID constant.

 

Does this involve every session variables? If that is the case how do i use a SID constant to transfer all my variables?

 

Link to comment
https://forums.phpfreaks.com/topic/275624-header/
Share on other sites

You declare a session as $_SESSION['session_name']. You missed the dollar sign. $_SESSION is a superglobal, just like $_SERVER which you used previously.

 

Take a look here:http://php.net/manual/en/language.variables.superglobals.php

 

Also, I'm pretty sure if you start a session in a file, then locate to a new file using a header() call, then you have to restart the session also with session_start(). If you locate to the new page with an include() or require(), you don't have to re-declare the session_start().

 

Depends what you want to do because obviously after including the file it will return to the calling script eventually.

 

Hope this helps.

 

Kind regards,

 

L2c.

Edited by Love2c0de
Link to comment
https://forums.phpfreaks.com/topic/275624-header/#findComment-1418458
Share on other sites

yea, i missed out the dollar sign while copying! :) it is in the original code.

There is no change in the pages except from i have changed the header goal from an direct URL to a PHP made url. Before i changed the code everything worked out as i wanted.

The Index.php has a "session_start()" at the veyr start so it s re-declared every time the page is refreshed. 

Link to comment
https://forums.phpfreaks.com/topic/275624-header/#findComment-1418460
Share on other sites

Run a var_dump() on $uri just after setting it. It's returning an empty string for me even though when I do print_r($_SERVER), there is a value in theat index.

 

There is a problem which lies in your dirname() call I think, you are passing a filename when you should be passing a directory name. Whether it is affecting it I don't know because you seem adamant you are successfully getting to the header page and the only place you use the $uri variable is in the header call..

 

Kind regards,

 

L2c.

Edited by Love2c0de
Link to comment
https://forums.phpfreaks.com/topic/275624-header/#findComment-1418465
Share on other sites

i did a var_dump() on all 3 variables:

string(15) "www.bahrawy.net"

string(13) "/dev/ballroom"

string(9) "index.php"

 

echo $host.$uri."/".$page;

www.bahrawy.net/dev/ballroom/index.php

 

I can't see the the difference between these two:

 - header("Location: http://$host$uri/$page");

 - header("Location: http://www.bahrawy.net/dev/ballroom/index.php");

 

and thanks for the help by the way! :)

Edited by fesan
Link to comment
https://forums.phpfreaks.com/topic/275624-header/#findComment-1418667
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.