Click here to Skip to main content
15,891,513 members

Comments by FRS4002 (Top 67 by date)

FRS4002 20-Jun-23 4:43am View    
filters.php is a page inside another page called all-products.php. filters.php is not really a page but it is just contains a list of main categories and sub categories in a box in the left side of all-products.php page. So, user can click on a main category and it leads to a page like:
https://test.com/main-category?cat=72

this appears in the url that has the products of this main category according to the id which is here cat=72. So, header("Location:" .$newURL); didn't work there.
FRS4002 19-Jun-23 1:14am View    
I added header("Location:" .$newURL); at the beginning of the page of main-category.php, but I still getting Internal Server Error. Here is the code of filters.php just in case:
      $sql1 = $db->prepare("SELECT * FROM categories WHERE id IN (SELECT parent FROM categories) AND parent = ? AND deleted = ?");
      $sql1->bind_param('ii', $var0, $var0);
      $sql1->execute();
      $result1 = $sql1->get_result();
      while($row1 = mysqli_fetch_assoc($result1)){
      $currentURL = "https://test.com/main-category?cat=".$row1['id'];
      $parsedURL = parse_url($currentURL);
      $baseUrl = $parsedURL['scheme'] . '://' . $parsedURL['host'] . $parsedURL['path'];
      $newPath = "/".str_replace(' ', '-', strtolower($row1['category']));;
      $newQuery = '';
      if(isset($parsedURL['query'])){
        parse_str($parsedURL['query'], $queryArray);
        unset($queryArray['cat']);
      $newQuery = http_build_query($queryArray);
 }
if($newQuery){
    $newURL = $baseUrl . $newPath . '?' . $newQuery;
    }else{
    $newURL = $baseUrl . $newPath;
}
  ?>

  <h6 style="margin-left: 10px;"><a href="<?=$newURL;?>"><?=$row1['category'];?></a></h6>


Of course, I replaced test with my domain. In the address bar the URL has changed... But there is no content with Internal Server Error. Maybe I need to receive the query string value in main-category.php, but how this can be done?
FRS4002 18-Jun-23 8:59am View    
Yeah, I understand the code and I applied the code in filters.php and it changed the URL. Now how to receive the new URL in main-category.php ? In other words, how main-category.php page will receive the new URL so it opens? Because, when I click on the link it says internal error.
FRS4002 17-Jun-23 15:02pm View    
Thanks for the clarification. But where should I put these codes? Is it in filters.php or in main-category.php? As I said before, this code:
<h6 style="margin-left: 10px;"><a href="main-category?cat=<?=$row1['id'];?>"><?=$row1['category'];?></a></h6>

is in filters.php that leads to main-category.php page... I should add/edit some code in this line above so it leads to what you said above...
FRS4002 17-Jun-23 8:04am View    
hair-care-categories is just an example... hair-care-categories is dynamic and coming from the database so it could be other than hair-care-categories.