לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #1  
ישן 27-02-2009, 13:02
  itzikc20 itzikc20 אינו מחובר  
 
חבר מתאריך: 10.04.05
הודעות: 235
הוצאת קוד מקור מדף חיצוני למשתנה

אני מנסה כבר המון זמן לנסות להוציא קוד מקור של אתר חיצוני כדי לקחת מידע כולשהוא שחיוני לאתר שלי, עכשיו אני לא מצליח אף פעם לעשות את זה ניסיתי עם IFRAME ועם AJAX. מישהו יכול להגיד לי איך אני יכול לנסות לעשות את זה? ולמה לדוגמא זה לא עובד לי? יש לציין שזה עובד אם אני לוקח קובץ מהשרת שלי ולא קובץ חיצוני.
קוד PHP:
 <head>
<
script type="text/javascript" src="ajaxroutine.js">
/***********************************************
* Basic Ajax Routine- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
</script>

<script type="text/javascript">
function processGetPost(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
if (myfiletype=="txt")
alert(myajax.responseText)
else
alert(myajax.responseXML)
}
}
}
</script>

</head>
<body>
<p align="left"><a href="#" onclick="ajaxpack.getAjaxRequest('http://www.devinrolsen.com/tutorials/ajax/instant_edit/index2.php', '', processGetPost, 'txt'); return false">Run example</a></p>
</body></html> 

the ajaxroutine.js:
קוד PHP:
 //Basic Ajax Routine- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated: Jan 15th, 06'

function createAjaxObj(){
var 
httprequest=false
if (window.XMLHttpRequest){ // if Mozilla, Safari etc
httprequest=new XMLHttpRequest()
if (
httprequest.overrideMimeType)
httprequest.overrideMimeType('text/xml')
}
else if (
window.ActiveXObject){ // if IE
try {
httprequest=new ActiveXObject("Msxml2.XMLHTTP");

catch (
e){
try{
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (
e){}
}
}
return 
httprequest
}

var 
ajaxpack=new Object()
ajaxpack.basedomain="http://"+window.location.hostname
ajaxpack
.ajaxobj=createAjaxObj()
ajaxpack.filetype="txt"
ajaxpack.addrandomnumber=//Set to 1 or 0. See documentation.

ajaxpack.getAjaxRequest=function(urlparameterscallbackfuncfiletype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (ajaxpack.addrandomnumber==1//Further defeat caching problem in IE?
var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
if (
this.ajaxobj){
this.filetype=filetype
this
.ajaxobj.onreadystatechange=callbackfunc
this
.ajaxobj.open('GET'url+"?"+parameterstrue)
this.ajaxobj.send(null)
}
}

ajaxpack.postAjaxRequest=function(urlparameterscallbackfuncfiletype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
if (this.ajaxobj){
this.filetype=filetype
this
.ajaxobj.onreadystatechange callbackfunc;
this.ajaxobj.open('POST'urltrue);
this.ajaxobj.setRequestHeader("Content-type""application/x-www-form-urlencoded");
this.ajaxobj.setRequestHeader("Content-length"parameters.length);
this.ajaxobj.setRequestHeader("Connection""close");
this.ajaxobj.send(parameters);
}
}

//ACCESSIBLE VARIABLES (for use within your callback functions):
//1) ajaxpack.ajaxobj //points to the current ajax object
//2) ajaxpack.filetype //The expected file type of the external file ("txt" or "xml")
//3) ajaxpack.basedomain //The root domain executing this ajax script, taking into account the possible "www" prefix.
//4) ajaxpack.addrandomnumber //Set to 0 or 1. When set to 1, a random number will be added to the end of the query string of GET requests to bust file caching of the external file in IE. See docs for more info.

//ACCESSIBLE FUNCTIONS:
//1) ajaxpack.getAjaxRequest(url, parameters, callbackfunc, filetype)
//2) ajaxpack.postAjaxRequest(url, parameters, callbackfunc, filetype)

///////////END OF ROUTINE HERE////////////////////////


//////EXAMPLE USAGE ////////////////////////////////////////////
/* Comment begins here

//Define call back function to process returned data
function processGetPost(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ if request was successful or running script locally
if (myfiletype=="txt")
alert(myajax.responseText)
else
alert(myajax.responseXML)
}
}
}

/////1) GET Example- alert contents of any file (regular text or xml file):

ajaxpack.getAjaxRequest("example.php", "", processGetPost, "txt")
ajaxpack.getAjaxRequest("example.php", "name=George&age=27", processGetPost, "txt")
ajaxpack.getAjaxRequest("examplexml.php", "name=George&age=27", processGetPost, "xml")
ajaxpack.getAjaxRequest(ajaxpack.basedomain+"/mydir/mylist.txt", "", processGetPost, "txt")

/////2) Post Example- Post some data to a PHP script for processing, then alert posted data:

//Define function to construct the desired parameters and their values to post via Ajax
function getPostParameters(){
var namevalue=document.getElementById("namediv").innerHTML //get name value from a DIV
var agevalue=document.getElementById("myform").agefield.value //get age value from a form field
var poststr = "name=" + encodeURI(namevalue) + "&age=" + encodeURI(agevalue)
return poststr
}

var poststr=getPostParameters()

ajaxpack.postAjaxRequest("example.php", poststr, processGetPost, "txt")
ajaxpack.postAjaxRequest("examplexml.php", poststr, processGetPost, "xml")

Comment Ends here */ 
_____________________________________
חתימתכם הוסרה כיוון שלא עמדה בחוקי האתר. לפרטים נוספים לחצו כאן. תוכלו לקבל עזרה להתאמת החתימה לחוקים בפורום חתימות וצלמיות.

תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #4  
ישן 28-02-2009, 18:06
  משתמש זכר dorM dorM אינו מחובר  
מנהל
 
חבר מתאריך: 26.07.08
הודעות: 6,473
בתגובה להודעה מספר 3 שנכתבה על ידי itzikc20 שמתחילה ב "[QUOTE=dorM]יכול להיות שהשרת..."

ציטוט:
במקור נכתב על ידי itzikc20
איך אני שולח כותרת כזאת?
ד"א זה לא עובד לי על כל אתר שאני מנסה, כאילו הפונ' עובדת רק על השרת עליו רצה הפונ'.


באותו היום שכתבתי פיתרון לבעיה שלך, היה במקום אחר למישהו אחר בעיה דומה בדיוק, ונתנו לו תגובה שזה לא אפשרי לשלוח בקשות דרך AJAX עבור domain אחר (other_domain.com) או אפילו host (החלק שנמצא איפה שה- www) אחר.

אתה יכול לחפש בגוגל באנגלית Cross domain ajax request.

ראה גם:
http://forums.digitalpoint.com/showthread.php?t=661755
http://www.bennadel.com/blog/1498-A...-ColdFusion.htm
http://stackoverflow.com/questions/...e-ajax-requests

הדפדפן עצמו מונע ממך לבצע דבר כזה מטעמי בטיחות של גניבת עוגיות או מידע אחר, בעיקר session id.

הפיתרון הוא לבצע את בקשת ה-ajax לקובץ בצד שרת אצלך, והקובץ בצד שרת יבצע את הבקשה בעצמו אל השרת החיצוני.

עריכה:
בנוגע לקביעת כותר בבקשה המתבצעת דרך AJAX, אז כמו שקבעת כותר בצורה הבאה:
קוד:
this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");


כך אתה יכול לקבוע כותרים אחרים:
קוד:
this.ajaxobj.setRequestHeader("Header_name", "value");
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #5  
ישן 28-02-2009, 19:46
  itzikc20 itzikc20 אינו מחובר  
 
חבר מתאריך: 10.04.05
הודעות: 235
בתגובה להודעה מספר 4 שנכתבה על ידי dorM שמתחילה ב "[QUOTE=itzikc20]איך אני שולח..."

ניסיתי עם Curl וקיבלתי קוד מקור טהור בלי קוקיז ודברים שיכולים לעזור לי, יש אפשרות להוציא קוד מקור של דף עם כל הדברים הנלווים שהדפדפן עצמו מתחבר? לדוגמא אם אני רוצה להציג דף שיראה את ההודעות הפרטיות שלי בפרש.... שאני רק יכנס אליו, בלי להיכנס עם הדפדפן עצמו לפרש... מקווה שהבנתם אותי הנה הקוד שהתשמשתי בו:
קוד PHP:
<?php
/**
 * Copyright (c) 2008, David R. Nadeau, NadeauSoftware.com.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *    * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *    * Redistributions in binary form must reproduce the above
 *      copyright notice, this list of conditions and the following
 *      disclaimer in the documentation and/or other materials provided
 *      with the distribution.
 *
 *    * Neither the names of David R. Nadeau or NadeauSoftware.com, nor
 *      the names of its contributors may be used to endorse or promote
 *      products derived from this software without specific prior
 *      written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGE.
 */

/*
 * This is a BSD License approved by the Open Source Initiative (OSI).
 * See:  http://www.opensource.org/licenses/bsd-license.php
 */


/**
 * Get a file on the web.  The file may be an (X)HTML page, an image, etc.
 * Return an associative array containing the page header, contents,
 * and HTTP status code.
 *
 * Values in the returned array are as defined by the CURL curl_getinfo()
 * function, and include:
 *
 *     "url"        the last effective URL after redirects
 *     "http_code"    the last error/status code
 *     "content_type"    the content type from the header
 *
 * This function adds a few more:
 *
 *     "content"    the page content (text, image, etc.)
 *     "errno"        the CURL error code
 *     "errmsg"    the CURL error message
 *
 * On success, "errno" is 0, "http_code" is 200, and "content" has the
 * web page.
 *
 * On an error with the URL, such as a redirect limit, or timeout,
 * "errno" will be non-zero and "errmsg" will contain an error message.
 * There other fields will be missing.
 *
 * On an error with the web site, such as a missing page, no permissions,
 * or no service, "errno" will be 0, "http_code" will be the HTTP error
 * code, and "content" will be missing.
 *
 * Parameters:
 *     url        the URL of the page to get
 *
 * Return values:
 *     An associative array containing the page text and error codes,
 *     as described above.
 *
 * See also:
 *    http://nadeausoftware.com/articles/2007/06/php_tip_how_get_web_page_using_curl
 */


function get_web_page$url )
{
    
$options = array(
        
CURLOPT_RETURNTRANSFER => true,     // return web page
        
CURLOPT_HEADER         => false,    // don't return headers
        
CURLOPT_FOLLOWLOCATION => true,     // follow redirects
        
CURLOPT_ENCODING       => "",       // handle compressed
        
CURLOPT_USERAGENT      => "spider"// who am i
        
CURLOPT_AUTOREFERER    => true,     // set referer on redirect
        
CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
        
CURLOPT_TIMEOUT        => 120,      // timeout on response
        
CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
    
);

    
$ch      curl_init$url );
    
curl_setopt_array$ch$options );
    
$content curl_exec$ch );
    
$err     curl_errno$ch );
    
$errmsg  curl_error$ch );
    
$header  curl_getinfo$ch );
    
curl_close$ch );

    
$header['errno']   = $err;
    
$header['errmsg']  = $errmsg;
    
$header['content'] = $content;
    return 
$header;
}

$url='http://www.fresh.co.il/vBulletin/usercp.php?';
$result get_web_page$url );

if ( 
$result['errno'] != ){
echo 
"error: bad url, timeout, redirect loop ...";}
    

if ( 
$result['http_code'] != 200 ){
   echo 
'error: no page, no permissions, no service ...';
}
else{
$page $result['content'];
echo 
$page;
}

?>
_____________________________________
חתימתכם הוסרה כיוון שלא עמדה בחוקי האתר. לפרטים נוספים לחצו כאן. תוכלו לקבל עזרה להתאמת החתימה לחוקים בפורום חתימות וצלמיות.

תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #6  
ישן 28-02-2009, 21:15
  משתמש זכר dorM dorM אינו מחובר  
מנהל
 
חבר מתאריך: 26.07.08
הודעות: 6,473
בתגובה להודעה מספר 5 שנכתבה על ידי itzikc20 שמתחילה ב "ניסיתי עם Curl וקיבלתי קוד..."

אהה הבנתי.

אני לא בטוח איך המערכת vBulletin עובדת, אבל כנראה היא מבצעת validation של עוגיית מזהה משתמש ועוגיית סיסמת משתמש.

עוגיית מזהה המשתמש (user id) נקראת "freshforumuserid".
עוגיית סיסמת המשתמש נקראת "freshforumpassword".
(אפשר למצוא זאת בקלות ע"י הסתכלות קצרה אל העוגיות בדפדפן שלך)

תסתכל בעוגיות הדפדפן שלך של הדומיין fresh.co.il, ותראה את הערך שנמצא בעוגיות האלו (הנ"ל שציינתי)
את שני הערכים האלה, מופרדים בסימן ";", תציב כערך של ה- cookie header בצורה הבאה:

קוד:
freshforumuserid=123456; freshforumpassword=your_password


את הפורמט של כותר ה-COOKIE אתה יכול לקרוא לדוגמא כאן: http://www.kuro5hin.org/story/2002/9/15/01845/1179

בדוגמא הנ"ל מצויין גם רווח אחד בין ה- ";" לעוגייה הבאה, לא יודע עד כמה זה קריטי...

השם של הכותר הוא פשוט "Cookie", ולא "Set-Cookie" כפי שאתה עשוי לחשוב, כי הרי את הכותר Set-Cookie אנו מקבלים (ב-reply) מהשרת web ש"אומר" לנו ליצור עוגיות מסוימות עם ערכים מסוימים, ואילו הכותר Cookie אנו שולחים אל שרת ה-web שיידע איזה עוגיות קיבלנו ממנו ומה הערכים שלהן.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 11:37

הדף נוצר ב 0.10 שניות עם 12 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2024 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר