Ghamdan
Members-
Posts
55 -
Joined
-
Last visited
Everything posted by Ghamdan
-
function redirct_none_admin($check ='user_id', $page='index.php'){ if(!isset($_SESSION[$check])) { $url = BASE_URL . $page; header("Location: $url"); exit(); } elseif($_SESSION['user_type'] != 'admin') { $url = BASE_URL . $page; header("Location: $url"); exit(); } } ======================================== It is working but I do not know if it is the right way to do it.
-
I am trying to create a script that redirect the none admin users. The code below: session_start(); function redirct_none_admin($check ='user_id', $target='index.php'){ if(!isset($_SESSION[$check])) { $url = BASE_URL . $target; header("Location: $url"); exit(); } } function call: // Redirect non-administrators: redirct_none_admin('user_admin'); I could not redirect the none-admin user. Is there anything wrong with this code? How to fix it? Thank you.
-
I am trying to use mode_rewrite in my project but it is not working. httpd.conf Settings: <Directory "C:/xampp/htdocs/mysite/blog"> AllowOverride All </Directory> .htaccess Settings: <IfModule mod_rewrite.co> RewriteEngine on RewriteBase /mysite/blog/ # For article: RewriteRule ^article/([0-9]+)/?$ article.php?id=$1 </IfModule> How can I fix this problem? Thank you.
-
Thank you. The query for page which lists the posts: $q = "SELECT post_id, views ,author, title, content, DATE_FORMAT(date_added, '%M %d, %Y') AS posted FROM posts ORDER BY date_added DESC "; Single post: // views counter: $q = 'UPDATE posts SET `views` = `views`+1 WHERE post_id='.$_GET['id']; $r = mysqli_query($dbc, $q); $q = 'SELECT views, author, title content, DATE_FORMAT(date_added, "%M %d, %Y") AS posted FROM posts WHERE post_id=' . $_GET['id'];
-
// views counter: $q = 'UPDATE posts SET `views` = `views`+1 WHERE post_id='.$_GET['id']; $r = mysqli_query($dbc, $q); This code works fine and I have noticed that when the page is viewed the order of posts in the main page (view_posts.php) changes according to the last post viewed. Although mysql query sets the order by to date_added DESC. The problem is that the last post viewed or displayed goes first in list. How can I fix this issue ? Thank you.
-
Sorry Antonio. I really got stuck. There is column named views I have done a separate queries as you can see below <article> <h1>Most popular post </h1> <?php // Get value from GET array $p_id = intval($_GET['id']); // This will be post_id 10 if you use the link above // Set queries $q = "SELECT * FROM testposts WHERE post_id = {$p_id} LIMIT 1"; $q .= "UPDATE testposts SET views=(views+1) WHERE post_id = {$p_id}"; // Notice .= here. This means it will be added to first string // run both queries $r = @mysqli_multi_query($dbc, $q); $q = "SELECT post_id, title, views FROM testposts ORDER BY views DESC LIMIT 4"; $r = @mysqli_query($dbc, $q); // If it ran OK : if($r) { while($row = mysqli_fetch_array( $r, MYSQLI_ASSOC )) { echo ' <p> <a href="article.php?id='. $row['post_id']. '"> Latest: ' . $row['title']. ' </a> </p>'; } } else { echo 'There is no post at the moment!'; } ?> </article> Thank you for trying to help me.
-
Thank you Antonio, I have done the following but it is not working. <?php // Counting the views: $p_id = intval($_GET['id']);// post id variable. $q = "SELECT post_id, title FROM posts WHERE post_id ={$p_id} LIMIT 5"; $q .= "UPDATE posts SET views=(views+1) WHERE post_id = {$p_id}"; // run both queries $r = @mysqli_multi_query($dbc, $q); // If it ran OK : if($r) { while($row = mysqli_fetch_array( $r, MYSQLI_ASSOC )) { echo ' <p> <a href="article.php?id='. $row['post_id']. '"> ' . $row['title']. ' </a> </p>'; } } else { echo 'There is no post at the moment!'; } ?>
-
I am trying to retrieve the most viewed post (popular) but it is not working. Is this syntax right? // Retrieve the most viewed post $q = " SELECT post_id ,title COUNT(title) AS most FROM posts GROUP BY title ORDER BY most DESC LIMIT 5"; $r = @mysqli_query($dbc, $q); if($r) { while($row = mysqli_fetch_array( $r, MYSQLI_ASSOC )) { echo ' <p><a href="article.php?id='. $row['post_id']. '"> ' . $row['most']. ' </a> </p>'; } =========================================== Thank you