Jump to content

Recommended Posts

Hi

 

I need to make a session if the URL paremeter has source=aw in the string.

 

I have this code

 

if ($_REQUEST["source"]=="aw"){

$_SESSION['affon']=1;

}

 

Then on any other PHP page or the same page on the same server folder I try echoing the file with no luck.

 

echo $_SESSION["affon"];

Link to comment
https://forums.phpfreaks.com/topic/243476-php-session-wont-echo/
Share on other sites

I can have this:

 

/site/john.php

 

Source:

 

<?php
session_start();
if ($_REQUEST["source"]=="aw"){
	$_SESSION['affon']=1;	
}
?>

 

If I try now making a file on the same server. Example

 

/site/sub/sarah.php

 

Source:

 

<?php
echo $_SESSION["affon"];
?>

 

The file won't work and won't register that a session is on the server. I thought PHP has it's own Memory??

/site/sub/sarah.php

 

Source:

 

<?php
echo $_SESSION["affon"];
?>

 

The file won't work and won't register that a session is on the server. I thought PHP has it's own Memory??

 

As I said above, you need session_start() at the top of all scripts, that's why it isn't working.

What do you mean registered the session?

 

I am just saying is there no other way to have session calls through the server on other PHP files without using the session start at the top....

 

That is all I wanted to know. I just want to know why PHP you need to declare a session_start(); every file.

 

I used to code PHP a long time ago; I remember the nasty ?PHPSESSIONID and other URLs which I definatley do not want users or search engines to see on my app

PHP session solves this problem by allowing you to store user information on the server for later use (i.e. username, shopping cart items, etc). However, this session information is temporary and is usually deleted very quickly after the user has left the website that uses sessions.

 

It is important to ponder if the sessions' temporary storage is applicable to your website. If you require a more permanent storage you will need to find another solution, like a MySQL database.

 

Sessions work by creating a unique identification(UID) number for each visitor and storing variables based on this ID. This helps to prevent two users' data from getting confused with one another when visiting the same webpage.

 

Note:If you are not experienced with session programming it is not recommended that you use sessions on a website that requires high-security, as there are security holes that take some advanced techniques to plug.

 

Starting a PHP Session

Before you can begin storing user information in your PHP session, you must first start the session. When you start a session, it must be at the very beginning of your code, before any HTML or text is sent.

http://php.net/manual/en/function.session-start.php

http://www.w3schools.com/php/php_sessions.asp

Ps. Learn to google it; you will get more more answer.

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.