Jump to content

irkevin

Members
  • Posts

    295
  • Joined

  • Last visited

Posts posted by irkevin

  1. Fixed

     

    here's how i did it.. again it was a str_replace :D

     

    on deinit.php:

     

    <?php
    
    function urlRewriteCallback($match) {
    $extra = '';
    if ($match[3]) {
    	$params = explode('&', $match[3]);
    
    	if ($params[0] == '') array_shift($params);
    	foreach ($params as $param) {
    		$paramEx = explode('=', $param);
    
    		$extra .= $paramEx[1].'/';
    
    	}
    }
    
    	return BASE_URL.$match[1].'/'.$extra;
    } 
    
    
    
    $pageContents = ob_get_contents();
    ob_end_clean();
    
    $pregit = preg_replace_callback($urlPatterns, 'urlRewriteCallback', $pageContents); 
    
    $preg = str_replace('index/','',$pregit);
    
    echo $preg;
    ?>
    

  2. ive noticed an extra semicolumn after the insert query

     

    "INSERT INTO `b33_3176976_lunadb`.`DB_Guides` (`gid`, `uname`, `gname`, `icon`, `desc`, `cat`, `body`, `score`) VALUES (NULL, \'$_POST['name']\', \'$_POST['guidename']\', \'$_POST['icon']\', \'$_POST['description']\', \'$_POST['cat']\', \'$_POST['body']\', \'0\');";

     

    try this

     

    $con = mysql_connect("xxxxxxxxxxx","xxxxxxxx","xxxxxxxxxxx");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }else{
    echo "Connected to DB";
    }
    
    
    $sql = "INSERT INTO `b33_3176976_lunadb`.`DB_Guides` (`gid`, `uname`, `gname`, `icon`, `desc`, `cat`, `body`, `score`) VALUES (NULL, \'$_POST['name']\', \'$_POST['guidename']\', \'$_POST['icon']\', \'$_POST['description']\', \'$_POST['cat']\', \'$_POST['body']\', \'0\')";
    
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record added";
    
    mysql_close($con);
    

     

  3. Hi

     

    I have a code that will convert my Dynamic urls to static.. I've already used mod_rewrite which is ok but now have to use php to convert them according to the rewrited one.

     

    However with php, instead of having this:

     

    http://www.mu-anime.com/page/OngoingAnime/

     

    I'm having this:

     

    http://www.mu-anime.com/index/page/OngoingAnime/

     

    The 'index' is to much there and i dont have a clue how to remove it. Below are the relevant codes

     

     

    init.php

    define('BASE_URL', 'http://www.mu-anime.com/'); // this you must use as an absolute path to the application root, ex: /folder1/folder2/
    
    if (isset($_SERVER['PATH_INFO'])) {
    $url = substr($_SERVER['PATH_INFO'], 1);
    $urlParts = explode('/', $url);
    if ($urlParts[count($urlParts) - 1] == '') array_pop($urlParts);
    
    $urlPartsCount = count($urlParts);
    if ($urlPartsCount % 2 != 0) {
    	$urlPartsCount++;
    }
    for ($i = 0; $i < $urlPartsCount; $i += 2) {
    	$_GET[$urlParts[$i]] = $urlParts[$i + 1];
    }
    } 
    
    $urlPatterns = array(
    '~'.preg_quote(BASE_URL).'([^\.]+[0-9a-zA-Z]+).php(\?([0-9a-zA-Z]+[^#"\']*))?~i',
    ); 
    
    
    ob_start();

     

    deinit.php

    function urlRewriteCallback($match) {
    $extra = '';
    if ($match[3]) {
    	$params = explode('&', $match[3]);
    	if ($params[0] == '') array_shift($params);
    	foreach ($params as $param) {
    		$paramEx = explode('=', $param);
    		$extra .= $paramEx[0].'/'.$paramEx[1].'/';
    	}
    }
    return BASE_URL.$match[1].'/'.$extra;
    } 
    
    
    $pageContents = ob_get_contents();
    ob_end_clean();
    echo preg_replace_callback($urlPatterns, 'urlRewriteCallback', $pageContents); 
    

     

    Someone help me with this please :(

  4. Well, there might ber some sort of solution, but that should give you an idea..  :D

     

    <?php
    $my_pages = array('home', 'music', 'stuffs', 'aboutus');
    
    // check that $_GET['page'] is present, if its not we'll setup a default page
    if(isset($_GET['page'])) && !empty($_GET['page']))
    {
        $requested_page = strtolower($_GET['page']);
    }
    else // $_GET['page'] not found or is empty, so we'll setup a default page to be requested 
    {
        $requested_page = 'home';
    }
    
    // setup an array of all your sites pages
    $my_pages = array('home', 'music', 'stuffs', 'aboutus');
    
    $requested_page = strtolower($_GET['page']);
    
    // make sue the request page is in $my_Pages array
    if(in_array($requested_page, $my_pages))
    {
        // the requested page will be included from a folder called my_pages in your websites root folder.
        // I assume the files to be included are html files
        include $_SERVER['DOCUMENT_ROOT'] . '/my_pages/' . $requested_page . 'html';
    }
    else
    {
        // requested_page not found
        die( 'The requested page (' . $requested_page ') was not found!' );
    }
    ?>
    

     

  5. you might want to try this

     

    
    $page = $_GET['page'];
    
    if(isset($page))
    {
        switch($page)
        {
         case 'home':
         
         echo "this is home";
         break;
    
         case 'page2':
         
         echo "this is page2";
         break;
    
         case 'page3':
         
         echo "this is page3";
         break;
      }
    }
    else
    {
         echo "this is home page which is the default";
    }
    
    <a href="index.php">home</a>
    <a href="index.php?page=page2">Page 2</a>
    <a href="index.php?page=page3">Page 3</a>
    

     

     

    try this and let me know

  6. not sure it will work

     

    but try to return the row variable

     

    <?php
    
    function get_user_name_from_db($user_id)
    {
      $qry = "SELECT * FROM user_tbl where user_id = '$user_id' ";
      $result = mysql_query( $qry ) or die(mysql_error());
      $row = mysql_fetch_assoc($result)or die (mysql_error());
      $user_name = $row['last_name'] . ", " . $row['first_name'];
      return $row;
    }
    
    ?>
    
    

     

    i dont guarantee this. it's been a while since i didnt touch php

  7. thars correct.. but i also need to put them that way on my website if i want users to navigate mu site using static urls.. how do i do this when having stuff coming from database?

     

    there must be a way to do this in php also.

  8. Well, what do  you recommend to use for doing this?

     

    I'm trying to make my links more friendly for google.. SEF i supose.

     

    I've been able to use htaccess to convert the links from dynamic to static.. but now, i have to convert them on my website also so that people can access the static one. .

     

    Do you get it now?

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.