help regarding all this pls!!

Started on the old forum in June 2012 · view the original in the archive · old links redirect here

20 replies · 1,202 views · started 14 years ago · 1 min read

7 participants
icedroplet1987 Senior · 258 posts #1

friends anybody can help me making session unexpired likewise here coding-talk?? my session get expire soon.. i want it like it wont get expire even if browser restart and also, if user inactive then wont appear online.. few users let open main page n be on it for long then they should out of site but whenever they refresh.. they do not get error of session expire.. hope you all got my point !!

and please also tell its side-effects (harms)!!

lastly, how can i redirect my users on same page from where he posted data.. like he shout on main page then should return on main page.. i am using should as function defined in core.php .. i am using shoutbox on different pages.. how can i return my users on same page, like if he post shout from buddylist then on buddylist, if main page, then on main page, if forums then on forums!! help me with proper solution..

thank you all in advance my all good coding-talk friends n experts:) help me please!!

shushant Developer · 207 posts #2

icedroplet1987 wrote: friends anybody can help me making session unexpired likewise here coding-talk?? my session get expire soon.. i want it like it wont get expire even if browser restart and also, if user inactive then wont appear online.. few users let open main page n be on it for long then they should out of site but whenever they refresh.. they do not get error of session expire.. hope you all got my point !!

and please also tell its side-effects (harms)!!

lastly, how can i redirect my users on same page from where he posted data.. like he shout on main page then should return on main page.. i am using should as function defined in core.php .. i am using shoutbox on different pages.. how can i return my users on same page, like if he post shout from buddylist then on buddylist, if main page, then on main page, if forums then on forums!! help me with proper solution..

thank you all in advance my all good coding-talk friends n experts:) help me please!!

if u want to keep logged in use cookie

icedroplet1987 Senior · 258 posts #3

shushant wrote: if u want to keep logged in use cookie

pls explain bro.. how do i do it? n also, any harm with it?? what abt other question.. redirection to same submit form after completing action?

Ghost Senior · 366 posts #4

using something like this works fine for me. does exactly what i expect it to do.

          	/** If Username And Password Is Correct Set Sessions */
		$_SESSION["valid_user"] = $Name;
        $_SESSION["valid_time"] = time();

/////
////
///

basically i stay logged in permanently, until 1 of 2 things happen. i click logout and end/destroy session. or the browser is disconnected from server for a lengthy ammount of time.

i recently created a function using this method.

 /** Login */
function login($Name, $Password)
{
$Password = crypt($Password,'password');
$Password_File = file('core/databases/data/passwords.txt');
$Username_File = file('core/databases/data/usernames.txt');
for ($k=0; $k<count($Username_File); $k++) 
{
    if (rtrim($Password_File[$k]) == $Password && rtrim($Username_File[$k]) == $Name)
{
          	/** If Username And Password Is Correct Set Sessions */
		$_SESSION["valid_user"] = $Name;
        $_SESSION["valid_time"] = time();
}
  }
} /** End Login Function */
//
//
//
//

then on page its used on.

  /** If Form Was submitted */
if (isset($_POST['submit']))
{ /** Call Security Function */
$Name = Security($_POST['Name']);
$Password = Security($_POST['Password']);
/** Call Login Function */
login($Name, $Password);
}

///
//

//
//

now obviously i know you cant use my exact function. it does however show how example 1 is used. basically not setting a set time for session to end.

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
icedroplet1987 Senior · 258 posts #5

Ghost wrote: using something like this works fine for me. does exactly what i expect it to do.

          	/** If Username And Password Is Correct Set Sessions */
		$_SESSION["valid_user"] = $Name;
        $_SESSION["valid_time"] = time();

/////
////
///

basically i stay logged in permanently, until 1 of 2 things happen. i click logout and end/destroy session. or the browser is disconnected from server for a lengthy ammount of time.

i recently created a function using this method.

 /** Login */
function login($Name, $Password)
{
$Password = crypt($Password,'password');
$Password_File = file('core/databases/data/passwords.txt');
$Username_File = file('core/databases/data/usernames.txt');
for ($k=0; $k<count($Username_File); $k++) 
{
    if (rtrim($Password_File[$k]) == $Password && rtrim($Username_File[$k]) == $Name)
{
          	/** If Username And Password Is Correct Set Sessions */
		$_SESSION["valid_user"] = $Name;
        $_SESSION["valid_time"] = time();
}
  }
} /** End Login Function */
//
//
//
//

then on page its used on.

  /** If Form Was submitted */
if (isset($_POST['submit']))
{ /** Call Security Function */
$Name = Security($_POST['Name']);
$Password = Security($_POST['Password']);
/** Call Login Function */
login($Name, $Password);
}

///
//

//
//

now obviously i know you cant use my exact function. it does however show how example 1 is used. basically not setting a set time for session to end.

yeah didnt understand much bro.. but thing you mentioned.. i want my user offline as soon as they close browser n want them again logged in if they open browser.. like here coding-talk .. or another lavalair site also doing so.. thats why so interested to do it..

what bout redirection to similar submit pge from same action.. i want my user to complete the action then get redirected to the page where they were!! i mentioned i am using same action for shout but on many pages... so how i redirect users to same page.. like buddylist ashout then it will be on buddylist back, if main page then main page, if forums, then forum... etc.. help regarding this too!!

Added after 2 minutes:

post proper codes abt session stuff.. i will fix on my site.. so post proper.. i dont know valid_user you getting how? post what u sing n should fix on lavalair @ ghost bro:)

Ghost Senior · 366 posts #6

coding-talk dont even destroy session on browser close down for a good 10-15mins after. ive closed browser a number of times, and still been logged in about 10 mins later after restarting browser or even shutting pc down.

it just depends on the the servers default destroy time i suppose if you dont set a particular time/interval yourself.

as for the redirect thing.

depending how you got it set up.

if your using the if (isset($_POST['submit'])) method you could try something like.

  /** If Form Was submitted */
if (isset($_POST['submit']))
{ 
/** do your code business here. */

/** then use meta to redirect to same page. */
echo "<meta http-equiv=\"Refresh\" content=\"0; url=PATH/TO/FILE/IN/USE\" />";
}
//
//
//
//

just a suggestion.

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
icedroplet1987 Senior · 258 posts #7

Ghost wrote: coding-talk dont even destroy session on browser close down for a good 10-15mins after. ive closed browser a number of times, and still been logged in about 10 mins later after restarting browser or even shutting pc down.

it just depends on the the servers default destroy time i suppose if you dont set a particular time/interval yourself.

as for the redirect thing.

depending how you got it set up.

if your using the if (isset($_POST['submit'])) method you could try something like.

  /** If Form Was submitted */
if (isset($_POST['submit']))
{ 
/** do your code business here. */

/** then use meta to redirect to same page. */
echo "<meta http-equiv=\"Refresh\" content=\"0; url=PATH/TO/FILE/IN/USE\" />";
}
//
//
//
//

just a suggestion.

i know meta can do it but it cant be used to redirect user to the place from where he submitted!! meta will need url.. so url will be like main page.. then if somebody shout from buddylist then also he is getting redirect to main page.. i want users to back on same page from where they submitted..

and please tell me where to apply session stuff.. i want session like here!! pls tell for lavalair bro..:(

Ghost Senior · 366 posts #8

without any of us actually seeing the source code in mention your having issues with. all you'll keep getting is suggestions really. and you never really know. the suggestions could well be put into your script without you actually realizing it.

i say this alot lately. but to save a lengthy process of try this, try that, blah blah. please start adding the code/file you want help with in either code tags or attachments. you may find a quicker solution this way.

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
shushant Developer · 207 posts #9
setcookie('name','shushant',time() + (86400 * 7)); // 86400 = 1 day

retrive

echo 'Hello '.(!empty($_COOKIE['name']) ? $_COOKIE['name'] : 'Guest');
icedroplet1987 Senior · 258 posts #10

shushant wrote:

setcookie('name','shushant',time() + (86400 * 7)); // 86400 = 1 day

retrive

echo 'Hello '.(!empty($_COOKIE['name']) ? $_COOKIE['name'] : 'Guest');

where do i add this?? both and also, where to retrive..?? any harm using it?

shushant Developer · 207 posts #11

icedroplet1987 wrote: where do i add this?? both and also, where to retrive..?? any harm using it?

nope just add it too top of ur script nd yes cookie can be sproof just make sql validation

12345xmen Developer · 239 posts #12

add in ur login PHP nd for see how add see ulkoi forum script u got how add

$XTREME$ Developer · 82 posts #13

Increase your session expire time from your database , then ur session wanner be expire soon , hmm

love_444 Junior · 38 posts #14

icedroplet1987 wrote: i know meta can do it but it cant be used to redirect user to the place from where he submitted!! meta will need url.. so url will be like main page.. then if somebody shout from buddylist then also he is getting redirect to main page.. i want users to back on same page from where they submitted..

and please tell me where to apply session stuff.. i want session like here!! pls tell for lavalair bro..:(

hmmm you can use header function ... wit that you can send to any page you wish

{$location="lists.php?action=pending&sid=$siid";header("Location: ".$location);

skils are gained by practis http://myguruworld.com/

Ghost Senior · 366 posts #15

icedroplet1987 wrote: i know meta can do it but it cant be used to redirect user to the place from where he submitted!! meta will need url.. so url will be like main page.. then if somebody shout from buddylist then also he is getting redirect to main page.. i want users to back on same page from where they submitted..

and please tell me where to apply session stuff.. i want session like here!! pls tell for lavalair bro..:(

ok i know this is a little late. but i made this to check referer and redirect.

/** just change >> path/to/buddylist.php */
if($_SERVER['HTTP_REFERER'] == 'http://'.$_SERVER['SERVER_NAME'].'/path/to/buddylist.php')
{
  /** Your Execution code here that does what you want. */

  /** Then Can Use Meta Here Also To Redirect To A Totally Different Page */
 /** just change >> back/to/path/of/buddylist.php & content="0 to however many seconds to wait on redirect */
echo '<meta http-equiv="Refresh" content="0; url=back/to/path/of/buddylist.php" />';
} 
//
//
//
//
//
//
//

it checks that it was referered from the path set, does your execution code, then redirect to whether you want it to. tested and working.

you could also add an else{} to it also if wanted

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
asifnayem Developer · 119 posts #16
ini_set('session.cache_expire', 200000);
ini_set('session.cache_limiter', 'none');
ini_set('session.cookie_lifetime', 2000000);
ini_set('session.gc_maxlifetime', 200000); 

session_start();
session_regenerate_id();

try using longer value here. find session_start(); in your codes. use

ini_set('session.cache_expire', 200000);
ini_set('session.cache_limiter', 'none');
ini_set('session.cookie_lifetime', 2000000);
ini_set('session.gc_maxlifetime', 200000); 

before session_start(); and

session_regenerate_id();

after to make sure it regenerate the session_id. Hope this could help you.

love_444 Junior · 38 posts #17

y are you all going so much complicated just use simple thinks ... less headache and work fine get last location and from that with help of header you can do waht you was willing is that not simple

skils are gained by practis http://myguruworld.com/

Ghost Senior · 366 posts #18

using header to redirect is not the best practise expecially when the php file in question has header already set at top of script. you will be bombarded with cannot modify headers. header already sent by blah blah at line blah. error. and the post i made about using meta to redirect is so simple a child could do it.

removed last bit of my comment, due to seeing example in an earlier post

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
love_444 Junior · 38 posts #19

Ghost wrote: using header to redirect is not the best practise expecially when the php file in question has header already set at top of script. you will be bombarded with cannot modify headers. header already sent by blah blah at line blah. error. and the post i made about using meta to redirect is so simple a child could do it.

removed last bit of my comment, due to seeing example in an earlier post

ya you are correct but some old java browsers dont exicute meta tage.... and also if net is slow then it will take too long to get redirected.....

and yes what you said abot header location is correct .... im also facing same problem and using meta tag 😊 but on some hosting the heder function work fine like host geter and ewebguru krishna server .....

i was surprised how it work there and not for me .... 😳 im a noob so if i said any blender plzzz dont laugh at me 😢

skils are gained by practis http://myguruworld.com/

Ghost Senior · 366 posts #20

love_444 wrote: but on some hosting the heder function work fine like host geter and ewebguru krishna server ..... i was surprised how it work there and not for me .... 😳 im a noob so if i said any blender plzzz dont laugh at me ;(

most probably down to the server not producing error logs.

ive been on a few servers that dont log errors so doesnt show when error appears like header modifying. just like it wont show if you turn error report off yourself from inside the script.

now im using a more stricter ruling server that does error logging i learn from my past errors and no longer use header location "unless" the script im writing has no header code to start with. even if meta redirect is slower. i would prefer to use it over the chance of if someone uses my script on a strict server like mine and they get alot of error's it doesnt make me look like a good coder, it makes me look bad in the long run.

as the saying goes, its better to be safe. than sorry.

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close