2013-02-14 40 views
10

मेरे पास एक पृष्ठ है जो यूआरएल से अद्वितीय आईडी के आधार पर, उस आईडी के लिए MySQL डेटाबेस खोजना, उस पंक्ति से सभी जानकारी प्राप्त करने आदि, वास्तव में मानक वास्तव में एक संपत्ति के बारे में जानकारी प्रदर्शित करता है।PHP का उपयोग कर गतिशील रूप से एक HTML पृष्ठ कैसे उत्पन्न करें?

मैं सोच रहा था कि प्रत्येक डेटाबेस पंक्ति के लिए मैं एक HTML पृष्ठ कैसे बना सकता हूं, क्योंकि मुझे लगता है कि यह एसईओ के लिए बेहतर होगा? एक गतिशील पृष्ठ के बजाय कीवर्ड के साथ एकाधिक पेज होने?

मेरी संपत्तियों को साइट पर एक फॉर्म/अपलोड सिस्टम द्वारा डेटाबेस में जोड़ा जाता है, मैं सोच रहा था कि अपलोड पर पेज बनाना सबसे आसान हो सकता है, लेकिन सुझावों के लिए खुला हूं!

+0

लगता है कि आप –

+3

im करने के प्रयास में एक सीएमएस की जरूरत के बजाय (एक तरह से) बनाने के अपने ही, और अधिक कुछ भी – rpsep2

+0

कि आप किस भाषा वेब पृष्ठों कार्यक्रम के प्रयोग कर रहे हैं की तुलना में सीखने के लिए? – Pete

उत्तर

17

मैं सोच रहा था अगर/मैं कैसे कर सकते हैं ' प्रत्येक डेटाबेस पंक्ति के लिए एक HTML पृष्ठ बनाएं?

आपको केवल एक php फ़ाइल बनाने की आवश्यकता है जो एक HTML टेम्पलेट उत्पन्न करता है, उस पृष्ठ पर टेक्स्ट आधारित सामग्री क्या परिवर्तन करती है। उस पृष्ठ में आप POST या GET के माध्यम से पैरामीटर (जैसे पंक्ति आईडी) प्राप्त कर सकते हैं और फिर जानकारी डेटाबेस बना सकते हैं।

मुझे लगता है कि यह एसईओ के लिए बेहतर होगा?

गूगल के रूप में खोज इंजन की व्याख्या कि example.php?id=33 और example.php?id=44 विभिन्न पृष्ठों हैं, और हाँ, इस तरह से देखने के एसईओ बिंदु से एक प्रविष्टि पृष्ठ की तुलना में बेहतर है, तो आप सिर्फ कम से कम दो php फ़ाइलें जरूरत है (listing.php और single.php), क्योंकि listing.php से इस पृष्ठ को बेहतर लिंक है।

अतिरिक्त सलाह:

example.php?id=33 वास्तव में बदसूरत और बहुत एसईओ अनुकूल नहीं है, हो सकता है आप कुछ यूआरएल कोड को फिर से लिखने की जरूरत है। example/properties/property-name की तरह कुछ बेहतर है;)

+1

इसे स्वीकार कर लिया गया है क्योंकि यह कुछ अतिरिक्त जानकारी देता है जो उपयोगी है, धन्यवाद, बीमार होने पर बीमार कुछ कोशिश करें – rpsep2

7

आपकी आवश्यकता के अनुसार आपको एक HTML पृष्ठ गतिशीलता उत्पन्न करने की आवश्यकता नहीं है। यह .htaccess फ़ाइल द्वारा किया जा सकता है।

अभी भी इस उत्पन्न करने के लिए HTML पेज

<?php 

$filename = 'test.html'; 
header("Cache-Control: public"); 
header("Content-Description: File Transfer"); 
header("Content-Disposition: attachment; filename=$filename"); 
header("Content-Type: application/octet-stream; "); 
header("Content-Transfer-Encoding: binary"); 
?> 

आप किसी भी .html बना सकते हैं नमूना कोड है, .php फ़ाइल सिर्फ फ़ाइल के नाम में विस्तार बदल

3

आपको किसी भी गतिशील HTML पृष्ठ को उत्पन्न करने की आवश्यकता नहीं है, बस .htaccess फ़ाइल का उपयोग करें और URL को फिर से लिखें।

13

शायद ज़रुरत पड़े किसी उत्पन्न/वास्तविक HTML फ़ाइल बनाना चाहता है ...

$myFile = "filename.html"; // or .php 
$fh = fopen($myFile, 'w'); // or die("error"); 
$stringData = "your html code php code goes here"; 
fwrite($fh, $stringData); 
fclose($fh); 

का आनंद लें!

+0

मेरे पास एक दस्तावेज़ है यह एक 'एचटीएमएल' दस्तावेज़ मुद्रित करेगा। 'Html' दस्तावेज़ के साथ यह मुख्य 'php' दस्तावेज़ से चर आता है। मैं मुख्य php दस्तावेज़ से गतिशील रूप से बनाए गए 'html' दस्तावेज़ में चर कैसे मुद्रित कर सकता हूं? –

1

मेरा सुझाव है कि यूआरएल रीराइट मोड का उपयोग करने के लिए आपकी समस्या के लिए पर्याप्त है, मुझे एक ही समस्या है लेकिन यूआरएल रीराइट मोड का उपयोग करके और अच्छी एसईओ प्रतिक्रिया प्राप्त करना। मैं आपको एक छोटा सा उदाहरण दे सकता हूं। उदाहरण यह है कि आप वर्डप्रेस पर विचार करते हैं, यहां डेटा डेटाबेस में संग्रहीत है, लेकिन यूआरएल रीराइट मोड का उपयोग करके कई वर्डप्रेस वेबसाइटों को Google से अच्छी प्रतिक्रिया मिल रही है और रैंक भी मिला है।

उदाहरण: यूआरएल रीराइट मोड - डोमेन के बाद url rewrite mod - domain.com/?p=123 के साथ वर्डप्रेस यूआरएल।com/तरह domain.com/seo-url-rewrite-mod

{लेख के शीर्षक} मैं तुम्हें समझ लिया है मैं तुम क्या कहना

0

मैं सिर्फ परिवर्तन को रोकने के लिए कोड को अपडेट कर देंगे चाहते हैं लगता है, और करने के लिए इतना है कि आप देख सकते हैं स्पष्ट रूप से चल रहा है यह टिप्पणी ...

<?php 
include("templates/header.htm"); 

// Set the default name 
$action = 'index'; 
// Specify some disallowed paths 
$disallowed_paths = array('header', 'footer'); 
if (!empty($_GET['action'])) { 
    $tmp_action = basename($_GET['action']); 
    // If it's not a disallowed path, and if the file exists, update $action 
    if (!in_array($tmp_action, $disallowed_paths) && file_exists("templates/{$tmp_action}.htm")) 
     $action = $tmp_action; 
} 
// Include $action 
include("templates/$action.htm"); 

include("templates/footer.htm"); 
0

मैं इस के समान की तरह काम कर रहा है और मैं कुछ कोड है कि आप मदद कर सकता है की है। लाइव उदाहरण here और नीचे है, यह कोड है जिसका उपयोग मैं आपके संदर्भ में करने के लिए कर रहा हूं।

बनाने-page.php

<?php 

// Session is started. 
session_start(); 

// Name of the template file. 
$template_file = 'couples-template.php'; 

// Root folder if working in subdirectory. Name is up to you ut must match with server's folder. 
$base_path = '/couple/'; 

// Path to the directory where you store the "couples-template.php" file. 
$template_path = '../template/'; 

// Path to the directory where php will store the auto-generated couple's pages. 
$couples_path = '../couples/'; 

// Posted data. 
$data['groom-name'] = str_replace(' ', '', $_POST['groom-name']); 
$data['bride-name'] = str_replace(' ', '', $_POST['bride-name']); 
// $data['groom-surname'] = $_POST['groom-surname']; 
// $data['bride-surname'] = $_POST['bride-surname']; 
$data['wedding-date'] = $_POST['wedding-date']; 
$data['email'] = $_POST['email']; 
$data['code'] = str_replace(array('/', '-', ' '), '', $_POST['wedding-date']).strtoupper(substr($data['groom-name'], 0, 1)).urlencode('&').strtoupper(substr($data['bride-name'], 0, 1)); 

// Data array (Should match with data above's order). 
$placeholders = array('{groom-name}', '{bride-name}', '{wedding-date}', '{email}', '{code}'); 

// Get the couples-template.php as a string. 
$template = file_get_contents($template_path.$template_file); 

// Fills the template. 
$new_file = str_replace($placeholders, $data, $template); 

// Generates couple's URL and makes it frendly and lowercase. 
$couples_url = str_replace(' ', '', strtolower($data['groom-name'].'-'.$data['bride-name'].'.php')); 

// Save file into couples directory. 
$fp = fopen($couples_path.$couples_url, 'w'); 
fwrite($fp, $new_file); 
fclose($fp); 

// Set the variables to pass them to success page. 
$_SESSION['couples_url'] = $couples_url; 
// If working in root directory. 
$_SESSION['couples_path'] = str_replace('.', '', $couples_path); 
// If working in a sub directory. 
//$_SESSION['couples_path'] = substr_replace($base_path, '', -1).str_replace('.', '',$couples_path); 

header('Location: success.php'); 

?> 

आशा इस फाइल को मदद कर सकते हैं और संदर्भ के रूप में काम शुरू करने और अपनी परियोजना को बढ़ावा देने के।

0

यह मजाकिया लग रहा है लेकिन यह काम करता है।

<?php 
$file = 'newpage.html'; 
// Open the file to get existing content 
$current = file_get_contents($file); 
// Append a new person to the file 
$current .= "<!doctype html><html> 
<head><meta charset='utf-8'> 
<title>new file</title> 
</head><body><h3>New HTML file</h3> 
</body></html> 
"; 
// Write the contents back to the file 
file_put_contents($file, $current); 
?> 

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^