Posts Tagged ‘url’

Mengambil alamat address web url full beserta variabel

This item was filled under [ Code Snippet, PHP ]

Masalah:

Seringkali jika kita ke website halaman yang harus login, maka kita harus login terlebih dahulu untuk melihat isi konten tersebut, akan tetapi kita ingin supaya setelah login redirect ke halaman konten tadi.

Solusi:

kita butuhkan script untuk mengambil alamat url full lengkap beserta variabel-varibel nya, untuk disispkan pada hidden text yang isinya adalah alamat full url pada form login Anda, yang nantinya akan diredirect pada alamat web tersebut yaitu dengan cara memanggil php script berikut:

// Fungsi Ambil Full Web Address Beserta Variabel2nya
function jin_get_address() { 
	$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; 
	$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; 
	$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); 
	return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; 
}
 
function strleft($s1, $s2) { 
	return substr($s1, 0, strpos($s1, $s2)); 
}

UPDATE:
tambahan fungsi strleft, terimkasih kepada Adi Suwarso atas koreksinya :mrgreen:

Continue reading...

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...
Popularity: 9,903 views
Tagged with: [ , , , , , ]

Membuat alamat link URL menjadi cantik

This item was filled under [ Code Snippet, PHP ]

Rewrite URL adalah salah satu dari tenik SEO.
Berikut contoh simple pembuatan URL cantik menggunakan .htaccess

simpan file pada root folder project Anda dengan nama .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
 
RewriteRule ^(.*)$ index.php?do=$1 [QSA,L]

lalu pada file index.php Anda, mainkan aturan URL-nya.

contoh isi file index.php:

<?php
$do = explode ("/", $_REQUEST['do']);
$opsi = $do[0];
 
switch($opsi) {
	case 'home':
		require_once (PUB_DIR . 'home.php');
	break;
	case 'content':
		require_once (PUB_DIR . 'web_content.php');
	break;
	case 'subcontent':
		require_once (PUB_DIR . 'web_content_sub.php');
	break;
	case 'news':
		require_once (PUB_DIR . 'news.php');
	break;
	case 'news-detail':
		require_once (PUB_DIR . 'news-detail.php');
	break;
	case 'articles':
		require_once (PUB_DIR . 'articles.php');
	break;
	case 'article-detail':
		require_once (PUB_DIR . 'article-detail.php');
	break;
	case 'event':
		require_once (PUB_DIR . 'event.php');
	break;
	case 'event-detail':
		require_once (PUB_DIR . 'event-detail.php');
	break;
	case 'calendar':
		require_once (PUB_DIR . 'calendar.php');
	break;
	case 'testimonial':
		require_once (PUB_DIR . 'testimonial.php');
	break;
	case 'testimonial-sign':
		require_once (PUB_DIR . 'guestbook_sign.php');
	break;
	case 'product':
		require_once (PUB_DIR . 'product.php');
	break;
	case 'product_search':
		require_once (PUB_DIR . 'product_search.php');
	break;
	case 'contact':
		require_once (PUB_DIR . 'contact_us.php');
	break;
 
	case 'search':
		require_once (PUB_DIR . 'search.php');
	break;
 
	case 'download':
		require_once (PUB_DIR . 'download.php');
	break;
 
	case 'faq':
		require_once (PUB_DIR . 'faq.php');
	break;
	case 'sitemap':
		require_once (PUB_DIR . 'sitemap.php');
	break;
 
	default:
		require_once (PUB_DIR . 'home.php');
}

Semoga membantu :mrgreen:

Continue reading...

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5 out of 5)
Loading ... Loading ...
Popularity: 815 views
Tagged with: [ , , , , ]

Halaman ini di eksekusi dalam waktu 0.704 detik! (koneksi mayan kenceng nih...)