Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> skrypt, który ma się sam zalogować, ... zalogować i odczytać...
Morian
post
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 29.04.2006

Ostrzeżenie: (0%)
-----


napisałem skrypt, który za pomocą funkcji fopen() odczytuje bazę danych w xml'u spod adresu http://..../baza.xml. Problem w tym, że żeby odczytać tę bazę na tej stronie wymagana jest autoryzacja (hasło i login oczywiście mam), a ja nie bardzo wiem, jak skrypt ma się tam sam zalogować, a potem odczytać dane...
próbowałem przez wykorzystanie header(), ale nie da rady, bo od razu przekierowuje na tamtą stronę i nie odczytuje...; podobno muszę posłużyć się $_GET... i podono fukcję fopen() muszę zastąpić czymś innym...
bardzo proszę o pomoc i z góry dziękuję za wszyskie odpowiedzi.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 9)
kuna
post
Post #2





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 20.06.2004

Ostrzeżenie: (0%)
-----


cURL albo fsockopen
Go to the top of the page
+Quote Post
Morian
post
Post #3





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 29.04.2006

Ostrzeżenie: (0%)
-----


nie da rady
Go to the top of the page
+Quote Post
Hacker
post
Post #4





Grupa: Zarejestrowani
Postów: 225
Pomógł: 0
Dołączył: 1.11.2005

Ostrzeżenie: (0%)
-----


hmmm...
jeżeli fsockopen+fwrite+fread i/lub fgets nie da rady to jestem chińską księżniczką tongue.gif


--------------------
(\.../)This is Bunny
(O.o)Copy Bunny into your signature to help him...
(> <)...on his way to world domination
Go to the top of the page
+Quote Post
Athlan
post
Post #5





Grupa: Developerzy
Postów: 823
Pomógł: 12
Dołączył: 18.12.2005

Ostrzeżenie: (0%)
-----


Cytat(Morian @ 2006-04-29 14:07:46)
napisałem skrypt, który za pomocą funkcji fopen() odczytuje bazę danych w xml'u spod adresu http://..../baza.xml. Problem w tym, że żeby odczytać tę bazę na tej stronie wymagana jest autoryzacja (hasło i login oczywiście mam), a ja nie bardzo wiem, jak skrypt ma się tam sam zalogować, a potem odczytać dane...
próbowałem przez wykorzystanie header(), ale nie da rady, bo od razu przekierowuje na tamtą stronę i nie odczytuje...; podobno muszę posłużyć się $_GET... i podono fukcję fopen() muszę zastąpić czymś innym...
bardzo proszę o pomoc i z góry dziękuję za wszyskie odpowiedzi.

ten sam efekt chcę uzyskać w temacie http://forum.php.pl/index.php?showtopic=46112 - loguje się na pocztę i czyta messy


--------------------
Portfolio: Vgroup.pl | athlan.pl | Test.php.pl - sprawdź się z wiedzy o PHP i ułóż własne pytania!
Pomogłem? Kliknij pod postem.
Go to the top of the page
+Quote Post
Morian
post
Post #6





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 29.04.2006

Ostrzeżenie: (0%)
-----


próbuję za pomocą fsockopen, ale nie wychodzi... oto kod:
Kod
<?
include("config.inc.php");

$pass=$cfg['auth_user'];
$user=$cfg['auth_pass'];

$fp=fsockopen("www.strona.pl", 80, $errno, $errstr);
if (!$fp)
{
  echo "$errstr ($errno) \n";
  echo $fp;
}
else
{
  fputs($fp, "GET /bazy/baza.xml HTTP/1.1\r\n");
  fputs($fp, "Host: www.strona.pl\r\n");
  fputs($fp, "Authorization: Basic ".base64_encode("$pass:$user")."\r\n");
  fputs($fp, "Connection: close\r\n\r\n");
}

while ( $data = fread($fp,4096) )
{
  if (!xml_parse($xml_parser, $data, feof($fp)))
  {
    echo(sprintf("XML error: %s at line %d\n",
         xml_error_string(xml_get_error_code($xml_parser)),
         xml_get_current_line_number($xml_parser)));
    break;
  }
}
?>

może wiesz, gdzie tkwi błąd panie Hacker? z góry dzięki za pomoc.
Go to the top of the page
+Quote Post
Hacker
post
Post #7





Grupa: Zarejestrowani
Postów: 225
Pomógł: 0
Dołączył: 1.11.2005

Ostrzeżenie: (0%)
-----


Po pierwsze [ php ]

Po drugie najpierw odczytaj cały plik a potem go parsuj
  1. <?php
  2.  
  3.  $dane = file_get_contents;
  4. while (!feof($fp)) {
  5. $dane .= fread($fp, 8192);
  6. }
  7. if (!xml_parse($xml_parser, $dane, true))
  8.  {
  9.  echo(sprintf("XML error: %s at line %d\n",
  10. xml_error_string(xml_get_error_code($xml_parser)),
  11. xml_get_current_line_number($xml_parser)));
  12.  }
  13. ?>

Po trzecie może byś podał co wyświetla Ci skrypt co??

Ten post edytował Hacker 30.04.2006, 17:16:11


--------------------
(\.../)This is Bunny
(O.o)Copy Bunny into your signature to help him...
(> <)...on his way to world domination
Go to the top of the page
+Quote Post
Morian
post
Post #8





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 29.04.2006

Ostrzeżenie: (0%)
-----


1. tam oczywiście jest [php]
2. teraz już jest połączenie i odczytuje część danych, ale po odczytaniu pojawia się następujący komunikat: "XML error: not well-formed (invalid token) at line 1".
prawdopodobnie w pewnym momencie zrywa połączenie, ponieważ trzeba ustawić czas... próbowałem ustawić, ale nadal pojawia się komunikat "XML error: not well-formed (invalid token) at line 1" i odczytuje tyle samo danych... a oto kod:
[CODE][COLOR=red]
<?php
...
$fp=fsockopen("www.strona.pl", 80, $errno, $errstr, 80);
if (!$fp)
{
echo "$errstr ($errno) \n";
echo $fp;
}
else
{
$out="GET /bazy/lm.xml HTTP/1.1\r\n";
$out.="Host: www.strona.pl\r\n";
$out.="Authorization: Basic ".base64_encode("$pass:$user")."\r\n";
$out.="Connection: close\r\n\r\n";
fputs($fp,$out);
}

$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");

//stream_set_timeout($fp, 100);
while ( $data = fread($fp,4096) )//reading file
{
echo ($data);
stream_set_timeout($fp, 1000);
if (!xml_parse($xml_parser, $data, feof($fp)))
{
echo(sprintf("XML error: %s at line %d\n",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
break;
}
}//while
...
?>
Go to the top of the page
+Quote Post
Hacker
post
Post #9





Grupa: Zarejestrowani
Postów: 225
Pomógł: 0
Dołączył: 1.11.2005

Ostrzeżenie: (0%)
-----


z [ php ] chodziło mi o odpowiedni bbcode
podaj adres tej stronki, z której chcesz ściągnąć tego xml-a
  1. <?php
  2.  
  3. $fp=fsockopen("www.strona.pl", 80, $errno, $errstr, 80);
  4.  
  5. ?>

większego timeouta daj

Ten post edytował Hacker 30.04.2006, 18:06:40


--------------------
(\.../)This is Bunny
(O.o)Copy Bunny into your signature to help him...
(> <)...on his way to world domination
Go to the top of the page
+Quote Post
Morian
post
Post #10





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 29.04.2006

Ostrzeżenie: (0%)
-----


sorry, ale nie mogę podać ci adresu tej stronki;
teraz odczytuje wszystkie dane, ale wygląda na to, że parser nie wywołuje "startElement", "endElement" i "characterData"...questionmark.gif? a timeouta dawałem już większego i nic...
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 11:35