I'm facing some problem in registering sessions in php. After login if I validate a session exist or not it show me it doesn't exist and take me back to the login sceen.. I don't have access to .htaccess file so can't change the global veriables.
here is code for login page if(isset($_POST['submit'])) { $admin_name=$_REQUEST['adminname']; $npassword=$_REQUEST['password']; $password=md5($npassword); $query="SELECT * FROM admin where admin_name='$admin_name' and password='$npassword'"; $result=mysql_query($query); $row=mysql_fetch_assoc($result); $num=mysql_num_rows($result); if($num>='1') { session_register('admin_name'); session_register('id'); header("location: main_page.php"); } else { $msg="<B>Invalid Admin name and pssoword</B>"; } } its working fine and goes to main_page.php... but don't find any session registered there and come back to this page. below is code for main_page.php session_start(); $uid=$HTTP_SESSION_VARS['admin_name']; if($uid=="") { header("location:index.php"); } else{-------code----} here it goes back to index page any suggestions ??
Don't use session_register(), it's deprecated. Just like $HTTP_SESSION_VARS. Use $_SESSION and to assign a new session do: $_SESSION['foo'] = 'bar'; PHP: Then in the next page you can use it just like any other variable. echo $_SESSION['foo']; PHP: Also, have a look at www.php.net/mysql_real_escape_string - because your script allows SQL injection.
hi session is working now but got new problem with copy file at local its working perfect but online giving permission error here is code mkdir('$var, '0777'); copy('page',$var.'/page.php'); can anyone help ?
Please include as much details as possible. I can't do anything with "I got an error". Are you using session_start(); in all pages? If so, what error? What exactly happens?
this code is for account.php file where user goes after login <?session_start(); include("../includes/config.php"); //echo $email=$HTTP_SESSION_VARS['email']; echo $email=$_SESSION['first_name']; include('../includes/header.php'); ?> and this is login page code <?session_start(); include("../includes/config.php"); if($_POST['submit']||$_POST['submitmain']) { $email=$_POST['emaillogin']; $npassword=$_POST['password']; $password=md5($npassword); $queryl="SELECT * FROM `user-register` where `email`='$email' and `password`='$password' and status='1'"; $resultl=mysql_query($queryl); $rowl=mysql_fetch_row($resultl); $regid=$rowl['regid']; $email=$rowl['email']; $first_name=$rowl['first_name']; $last_name=$rowl['last_name']; $num=mysql_num_rows($resultl); if($num>=1) { ini_set('session.use_cookies',false); $_SESSION['first_name'] = $first_name; session_register('email'); session_register('first_name'); session_register('last_name'); session_register('regid'); header("location:account.php"); } else { header("location:login.php?msg=1"); } } include('../includes/header.php'); ?> It just take me to the account page with no error but not showing the username or session registered which i try to print.
<? session_start(); //account.php print_r($_SESSION); //dumps the session array www.php.net\print-r echo "<hr>"; //echo a horizontal rule //lets print out the session data in a more readable format now foreach ($_SESSION as $key => $value) { //www.php.net/foreach echo "Session Key:= " . $key . " - Session Value:= " . $value . "<br>"; } ?> PHP: The best thing you can do with any script when it goes wrong is to output your data and take it from there.
its showing me this Array ( => [last_name] => [regid] => [first_name] => ) Session Key:= emailSession Value:= Session Key:= last_nameSession Value:= Session Key:= regidSession Value:= Session Key:= first_nameSession Value:= no value in session
Anytime. Also you should post your fix then in the future people can search and use this thread for help. Also always remember to output things as soon as you hit an error you can not seem to fix. Saves much time and is good practise.