session start
Started on the old forum in May 2010 · view the original in the archive · old links redirect here
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... _______…
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
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?
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/>";
}
?>
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 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();
}
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.
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!
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']))){
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?
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!