Note that there are some explanatory texts on larger screens.

plurals
  1. POsession doesn't work properly
    primarykey
    data
    text
    <p>i having problem with sessions in localhost, the problem is the session doesn't work actually when it redirects to new post page it response's as you should login first </p> <p>Login code </p> <pre><code>&lt;?php include '../Class/db.class.php'; include '../Class/validation.class.php'; @session_start(); if(!$_SESSION['user']){ $link=$_GET['dir']; if($link){ echo &lt;&lt;&lt;EOF &lt;html&gt; &lt;head&gt;&lt;title&gt;ورود&lt;/title&gt;&lt;/head&gt;&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; &lt;form method='post' action='index.php?dir=$link'&gt; Username: &lt;input type='text' name='user'&gt;&lt;br /&gt; password&lt;input type='password' name='pass'&gt;&lt;br /&gt; &lt;input type='hidden' name='hidd' value=1&gt; &lt;input type='submit' value='login'&gt;&lt;br /&gt; &lt;/form&gt; EOF; } else { echo &lt;&lt;&lt;EOF &lt;html&gt; &lt;head&gt;&lt;title&gt;login&lt;/title&gt;&lt;/head&gt;&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; &lt;form method='post' action='index.php'&gt; username: &lt;input type='text' name='user'&gt;&lt;br /&gt; password: &lt;input type='password' name='pass'&gt;&lt;br /&gt; &lt;input type='hidden' name='hidd' value=1&gt; &lt;input type='submit' value='login'&gt;&lt;br /&gt; &lt;/form&gt; EOF; } } $db=new db("localhost", "root", "", "blog"); $con=$db-&gt;connect(); $logout=$_GET['logout']; $user=$_POST['user']; $pass=$_POST['pass']; $hidden=$_POST['hidd']; if($hidden){ if(!$user){ echo "username field can't left blank"; } elseif (!$pass) { echo 'password field can't left blank!'; } else{ $userres=$db-&gt;usersearch($user, $pass); if($userres==FALSE){ echo 'username or password is wrong'; } else { $_SESSION['user']=$user; } } } if($_SESSION['user']){ $link=$_GET['dir']; echo "you logged in ".$_SESSION['user']; if($link=="new") echo '&lt;meta http-equiv="REFRESH" content="0;url=../admin/post/new.php"&gt;'; } if($logout) session_destroy(); if($_SESSION['user']) echo '&lt;br /&gt;&lt;a href="?logout=1"&gt;logout&lt;/a&gt;'; ?&gt; </code></pre> <p>new post code</p> <pre><code>&lt;?php @session_start(); if($_SESSION['user']=="admin"){ include '../../Class/db.class.php'; echo &lt;&lt;&lt;EOF &lt;form method=post action="new.php"&gt; &lt;br /&gt; subject: &lt;br /&gt; &lt;input type="text" name="title"&gt;&lt;br /&gt; post:&lt;br /&gt; &lt;textarea cols=50 rows=10 name="post"&gt;&lt;/textarea&gt;&lt;br /&gt; &lt;input type="submit" value="send"&gt; EOF; $title=$_POST['title']; $post=$_POST['post']; $db=new db("localhost", "root", "", "blog"); $db-&gt;connect(); if($title &amp;&amp; $post){ $d=$db-&gt;post_insert($title, $title, 1); if($d==TRUE) echo "post created"; else echo "an error occurred while sending the post"; } $dd=$db-&gt;read(0, 20); for($i=0;$i&lt;20;$i++){ echo $dd['content'][$i]."&lt;br /&gt;"; } } else { echo "you should login first"; echo $_SESSION['user']; } /* * To change this template, choose Tools | Templates * and open the template in the editor. */ ?&gt; </code></pre> <p>please help me! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload