session start

Started on the old forum in May 2010 · view the original in the archive · old links redirect here

29 replies · 1,757 views · started 16 years ago · 1 min read

6 participants
realcoder Junior · 17 posts #1

i am writing my own script but my only problem is getting the session started as in sid=bla bla bla

how do i do it and if u dont do anything it logs you out is it a for loop or something

brandon rules the codeing industry

subzero Super moderator Fellow · 3,954 posts #2
session_start();
if(isset($_SESSION['sid']))
{
echo "Your logined in!";
}else{
echo " your not logined in !";
}
$_SESSION['id']=session_id();
$_SESSION['sid']=$sid;

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

realcoder Junior · 17 posts #3

i keep getting your logged out , do i need to define something else this is how i have it what am i doing wrong please someone assist me .

<?php session_start(); // session start ?> <?php include("conf.php"); // database setup info $con = mysql_connect("$dbhost","$dbuser","$dbpass"); if (!$con) { die('Could not connect: ' . mysql_error()); } $_SESSION['id']=session_id(); $_SESSION['sid']=$sid; if(!isset($_SESSION['sid'])) { echo "Your not logged in !"; exit(); } mysql_select_db("$dbname", $con); $usn = $_GET[usn]; $uinf = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM link_users WHERE username='".$usn."'")); if($uinf[0]==0) { echo " <img src=\"images/notok.gif\" alt=\"X\"/>UserName doesn't exist "; exit(); } else{ $sid = md5($sid); $usn = $_GET[usn]; echo "Logged in successfully as $usn "; echo "[Enter](#) "; } ?>

brandon rules the codeing industry

abipol Junior · 11 posts #4

ive already hide my own session id using $sid = $_SESSION['sid']. but my problem is how to redirect users to main page if their session still not expired?

simple things can be a great sample!

realcoder Junior · 17 posts #5

it keeps saying am noy logged in , bro remeber this is not the lavalair script am writing my own things like get_userid is not apart of my script thats why i am asking all the functions i need to define to get it working .

brandon rules the codeing industry

wap_king Developer · 126 posts #6

so ummm if i do this

session_start();

if(isset($_SESSION['username']))

{

echo "Welcome " . $_SESSION['username'];

//some codes here

}else{

echo "oops sorry your session has expire or is invalid"; }

What must i do to keep the user session if the user clicks a link on where it says welcome username how to make that session stay ? should i put session_start(); on all the pages?

something else Fellow · 2,296 posts #7

the page you are showing looks like a login page to me so it would be something like this:

<?php
session_start(); // session start

include("conf.php"); // database setup info
$con = mysql_connect("$dbhost","$dbuser","$dbpass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("$dbname", $con);
$usn = $_GET[usn];
$uinf = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM link_users WHERE username='".$usn."'"));
if($uinf[0]==0)
{
echo "<br/><img src=\"images/notok.gif\" alt=\"X\"/>UserName doesn't exist<br/><br/>"; 
}else{
$sid = time() +26565*4;
$_SESSION['sid'] = md5($sid); 
echo "Logged in successfully as $usn<br/><br/>";
echo "<a href=\"inc.php?ac=main\">Enter</a><br/>";
}
?>
something else Fellow · 2,296 posts #8

abipol wrote: ive already hide my own session id using $sid = $_SESSION['sid']. but my problem is how to redirect users to main page if their session still not expired?

few ways you can do it... delete the session in the database or set the session to a false session ef:

 $_SESSION['sid'] = "";

or unest the session:

session_unset();
session_destroy();
wap_king Developer · 126 posts #9

its not a loggin page its the main page i am wondering it is complete/ correct am using $_SESSION and i want it to say your session has expire if a user tries to enter the site without registering or loggining and also if the user session expires for real

something else Fellow · 2,296 posts #10

wap_king wrote: its not a loggin page its the main page i am wondering it is complete/ correct am using $_SESSION and i want it to say your session has expire if a user tries to enter the site without registering or loggining and also if the user session expires for real

ooooooh 2 nicks lol 🙂

you would have to check the SESSION against the session in the database. You havent given enough details like sql for it to be coded 🙂

An example of session checking with made up database fields:

$check = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM sessions WHERE sesionid='".$_SESSION['sid']."'"));

if($check[0]<1){
echo "u are nit logged in";
exit();
}
wap_king Developer · 126 posts #11

am not using sid am using $_SESSION

something else Fellow · 2,296 posts #12

i didnt use a $_GET variable i used a $_SESSION varible in my last post 😛

the sid is just a string which i use for an example it could be anything like:

$_SESSION['thebigredshineygoldfish'];

as long as you check the variable is matching against some data eg database then you can confirm that your logged in

if you just use if(isset($_SESSION['sid'])) then as long as $_SESSION['sid'] has a variable in it ... it is TRUE

in other words i put any number in the $_SESSION I would be instantly be logged in even if im not a member of your site.

sorry this post might sound a little confusing lol.

abipol Junior · 11 posts #14

something else wrote: few ways you can do it... delete the session in the database or set the session to a false session ef:

 $_SESSION['sid'] = "";

or unest the session:

session_unset();
session_destroy();

thank you. but i created function LoginPage(); here are some of the code.

if(empty($_SESSION['sid']) OR (!isset($_SESSION['sid']))){
echo LoginPage();
exit();
}

if users session still active or not expired user can access the requested page, but if users session already expired the login page will be display.

simple things can be a great sample!

something else Fellow · 2,296 posts #15

abipol wrote: thank you. but i created function LoginPage(); here are some of the code.

if(empty($_SESSION['sid']) OR (!isset($_SESSION['sid']))){
echo LoginPage();
exit();
}

Its not hard for me to add a session id into my browser myself .... so if i put into my browser sid=(anything) then im instantly logged into your site Thats why checking the session id against a database or some other data source is so important. Rather than just having if(empty($_SESSION['sid']) OR (!isset($_SESSION['sid']))){

abipol Junior · 11 posts #16

@something else, sid will never be created at database if user did not login. $_SESSION['sid'] its just a substitute to $sid. well thank you this is big help for me as a noob. thanks alot for the idea! 🙂

simple things can be a great sample!

wap_king Developer · 126 posts #17

something else wrote: ooooooh 2 nicks lol 🙂

you would have to check the SESSION against the session in the database. You havent given enough details like sql for it to be coded 🙂

An example of session checking with made up database fields:

$check = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM sessions WHERE sesionid='".$_SESSION['sid']."'"));

if($check[0]<1){
echo "u are nit logged in";
exit();
}

can you post the sql and the rest of that coding?

CreativityKills Lead · 833 posts #18

u gotta be fu.cking kidding me! They give u d code and u cant make a fu.ckn database table n column for it? Theres a phpmyadmin gui f.f.s! Lazy a.sswipe!

wap_king Developer · 126 posts #19

something else what whould the link be on the login page enter

thats all i need what should go on the login page

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