Solved

Update : question bug php

Posted on 2015-01-01
27
109 Views
Last Modified: 2015-01-02
HI

i finally got the probleme

HTTP/1.1 303 See other
Date: Fri, 02 Jan 2015 01:24:32 GMT
Server: Apache/2.2.22 (Debian)
X-Powered-By: PHP/5.4.35-0+deb7u2
Location: http://website.fr//index.php
Vary: Accept-Encoding,User-Agent
Content-Length: 0
Content-Type: text/html; charset=utf-8

HTTP/1.1 200 OK
Date: Fri, 02 Jan 2015 01:24:32 GMT
Server: Apache/2.2.22 (Debian)
X-Powered-By: PHP/5.4.35-0+deb7u2
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Cache-Control: no-cache
Pragma: no-cache
Vary: Accept-Encoding,User-Agent
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

Open in new window


The script does not receive the cookie of the line 59 - 94 and crash how to resolve the probleme ?

http://pastebin.com/R2NC4Sf3

i test with this line

 $header_size = curl_getinfo ($curl, CURLINFO_HEADER_SIZE);
    $header = substr ($html, 0, $header_size);
    print_r ($header);

Open in new window

0
Comment
Question by:hexo dark
  • 14
  • 8
  • 4
  • +1
27 Comments
 
LVL 76

Expert Comment

by:arnold
ID: 40527136
The header you posted does not have the set-cookie parameter the function for cookie setting is looking for.
0
 
LVL 57

Expert Comment

by:giltjr
ID: 40527137
Is the text you posted the some type of output from your PHP script?  Or is it the input to the script?

If it is the input, there are no cookies for your script to process.  If it is the output from your script, we would need to see the input.
0
 
LVL 2

Author Comment

by:hexo dark
ID: 40527150
On a forum we told me what am

It looks to me like the server isn't returning the cookie. You can read the headers thusly:
$header_size = curl_getinfo ($curl, CURLINFO_HEADER_SIZE);
$header = substr ($html, 0, $header_size);
print_r ($header);

Open in new window


résult
HTTP/1.1 303 See other
Date: Fri, 02 Jan 2015 01:24:32 GMT
Server: Apache/2.2.22 (Debian)
X-Powered-By: PHP/5.4.35-0+deb7u2
Location: http://website.fr//index.php
Vary: Accept-Encoding,User-Agent
Content-Length: 0
Content-Type: text/html; charset=utf-8

HTTP/1.1 200 OK
Date: Fri, 02 Jan 2015 01:24:32 GMT
Server: Apache/2.2.22 (Debian)
X-Powered-By: PHP/5.4.35-0+deb7u2
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Cache-Control: no-cache
Pragma: no-cache
Vary: Accept-Encoding,User-Agent
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
                                  

Open in new window


and
There's the answer as to why it's failing - you're not getting a cookie back and your program is expecting one.

is résult of the debug
http://pastebin.com/ysAuqnQ1

I did not create the script and thus I do not know everything of the script I have to make with what I know

for the input i do not have any idea sorry
0
 
LVL 2

Author Comment

by:hexo dark
ID: 40527175
oups error is not 59 - 94 is 141 - 146
$old = $cookie;
    get(SITE_URL . $videoLink);
 var_dump($cookie, $old);
    if ($cookie == $old)
    {
        die('Impossible de récupérer les tokens de la vidéo');
    }

Open in new window

we can see that the code has an expectation that the value of cookie will have changed after the call has been made and if it doesn't then the application fails.

In the get function:
$cookie .= getCookie($html);

Open in new window

The global variable $cookie has the returned cookie value appended to it but since no cookie value is returned then the value is unchanged so the test that is to follow will cause the application to die
die(Impossible to get  the tokens of the video');

Open in new window

0
 
LVL 57

Expert Comment

by:giltjr
ID: 40527186
We need to see what the browser is sending back to the server.

Based on what you have provided so far, there are no cookies to find.
0
 
LVL 2

Author Comment

by:hexo dark
ID: 40527192
We need to see what the browser is sending back to the server.

how to get this information ?
0
 
LVL 76

Assisted Solution

by:arnold
arnold earned 250 total points
ID: 40527198
the pattern matches should work and seem to work, as your latest debug report includes the Cookie in the Set-Cookie:
18acd9b63ecbf50de0b8c010c2b7289f=ft1vt2i1cclossnc303pdgqhk5
once your script Sends as part of your request the parameter:
Cookie: 18acd9b63ecbf50de0b8c010c2b7289f=ft1vt2i1cclossnc303pdgqhk5
The remote side, stops sending the Set-Cookie directive unless there is a change from the server, i.e. your script says Cookie: 123456. But the mechanism on the server sees it as invalid, and issues you back a response to Set-Cookie: to one that is valid.

FYI your uploaded script includes login information. not sure whether it is or is not valid.

But what is the issue that you are having/are looking to resolve?
When you run the script, the items you are looking to obtain are not validating?
0
 
LVL 2

Author Comment

by:hexo dark
ID: 40527206
oh shit ! ty i have update the code to removes the user pass

new link http://pastebin.com/3v3a6w1e

i got the information on the site web  

	
	[Object { name="Host", value="website.fr"}, Object { name="User-Agent", value="Mozilla/5.0 (X11; Linux ...o/20100101 Firefox/34.0"}, Object { name="Accept", value="text/html,application/xh...ion/xml;q=0.9,*/*;q=0.8"}, 5 plus...]
	Object { name="Host", value="website.fr"}
	Object { name="User-Agent", value="Mozilla/5.0 (X11; Linux ...o/20100101 Firefox/34.0"}
	Object { name="Accept", value="text/html,application/xh...ion/xml;q=0.9,*/*;q=0.8"}
	Object { name="Accept-Language", value="fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3"}
	Object { name="Accept-Encoding", value="gzip, deflate"}
	Object { name="Cookie", value="18acd9b63ecbf50de0b8c010...=54a613640d765343189874"}
	name "Cookie"
	value  "18acd9b63ecbf50de0b8c010c2b7289f=castip4cq1lo57tq665pjju3i1; _ga=GA1.2.2127250119.1420170074; _gat=1; YWRuLWF1dGhfNTE5Ml8w=54a613640d765343189874"
	Object { name="DNT", value="1"}
	Object { name="Connection", value="keep-alive"}

Open in new window


réponse

	Object { name="Date", value="Fri, 02 Jan 2015 03:41:40 GMT"}
	       Object { name="Server", value="Apache/2.2.22 (Debian)"}
	      Object { name="X-Powered-By", value="PHP/5.4.35-0+deb7u2"}
	Object { name="p3p", value="CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM""}
	Object { name="Cache-Control", value="no-cache"}
	Object { name="Pragma", value="no-cache"}
	Object { name="Vary", value="Accept-Encoding,User-Agent"}
	Object { name="Content-Encoding", value="gzip"}
	Object { name="Content-Length", value="14123"}
	Object { name="Keep-Alive", value="timeout=5, max=99"}
	Object { name="Connection", value="Keep-Alive"}
	Object { name="Content-Type", value="text/html; charset=utf-8"

Open in new window

0
 
LVL 2

Author Comment

by:hexo dark
ID: 40527215
I have to say saddened I express myself badly in English

But what is the issue that you are having/are looking to resolve?
I just try to run the code as before

When you run the script, the items you are looking to obtain are not validating?
For the moment given information it is only that I have
0
 
LVL 76

Expert Comment

by:arnold
ID: 40527217
if you are trying to download images, your list of images to download which is within the pngFilename variable is not being set/updated.

not  sure whether line 151  where you have the get() seemingly for the list of content it is missing the assignment to $html=get (...video .... )
see if that fixes the issue you are having.

are you trying to script a download or an upload?

as mentioned before, I do not see where you build the list of items for either one.
0
 
LVL 76

Expert Comment

by:arnold
ID: 40527219
when was it that script worked last?  The site may have changed such that what you are looking for is not longer there.
Navigate the site to confirm that your current script continues to follow the navigation of the site.
i.e. one of the last link you think is site_URL/video is actually now site_URL/somenewthing/video

are you getting error that the videos are not there?
0
 
LVL 2

Author Comment

by:hexo dark
ID: 40527222
i trying to download files  and get  2 order information for play video on my mediacenter

I am not sure to understand im a noobs

edit : ah i look this :)
0
 
LVL 2

Author Comment

by:hexo dark
ID: 40527230
the link is not change  /video/name/id is the same  :)
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 76

Expert Comment

by:arnold
ID: 40527232
Look at line 151 of the pastebin.com link you posted.  This is within the section getsecuritytokens.

I think it is missing the $html which will be used within download
it is now
151: get(SITE_URL . '/index.php?option=com_vodvideo&view=player&format=raw&video_id='.$videoId.'&load=1&date=');

but should be
151: $html=get(SITE_URL . '/index.php?option=com_vodvideo&view=player&format=raw&video_id='.$videoId.'&load=1&date=');

try the change and see if that works or not.

The difficulty is that it is not clear to me what the issue is that you are facing.

It is one thing to read through code, it is another to know how this code interacts with the site from which you want data.
0
 
LVL 2

Author Comment

by:hexo dark
ID: 40527238
sorry not work

The difficulty is that it is not clear to me what the issue is that you are facing.
I understand you I have from the difficulty to the knowledge too because I begin in the domain

It is one thing to read through code, it is another to know how this code interacts with the site from which you want data.
Not I who am made the script I also try to understand(include) and I do not manage to join his(her) creator he(it) not response not...
0
 
LVL 76

Expert Comment

by:arnold
ID: 40527240
What is it you expect this code to do? Download images/vidoes to your system or upload them?
Or do you have a website http://www.yourdomain.com where you placed this viewcontent.php

you are accessing http://www.yourdomain.com/viewcontent.php using your TV or computer, and you click on the link


ecrive en Francais, I'll translate what I do not understand using the various tools available on the web.

Are you getting this error, "Impossible de récupérer les tokens de la vidéo sur demande" and this is the issue?
0
 
LVL 2

Author Comment

by:hexo dark
ID: 40527241
yes is the error i have Impossible de récupérer les tokens de la vidéo sur demande
0
 
LVL 76

Expert Comment

by:arnold
ID: 40527242
The cookie==old is the reason, the script seems to look for a change in cookie.  I do not know whether it should or should not change.
Comment out lines 153-156
// in front of line 153, 154, 155 and 156
I think the process is looking for a change in the cookie data when requesting the info on line 151.
There is no way for me to know whether they used to add a cookie setting and now they stopped.
i.e. add another entry that is now not there.
0
 
LVL 2

Author Comment

by:hexo dark
ID: 40527244
je vais voir ce que je peux faire directement sur le site et vais revenir sur le sujet demain :)
I go to see what I can make directly on the site and am going to return on the subject tomorrow:)
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 125 total points
ID: 40527666
@hexo_dark, I see you've been working on this for a few days now, and you have my sympathy.  It took me a long time to understand HTTP cookies at first.  And my French is not good enough to explain it well, but maybe a code example will help.  If you want to get some background understanding of the HTTP protocol, this article may be helpful.  You need to understand the HTTP client/server model to understand the flow of data and control that occurs with cookies.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html

This is intended to be a very simple teaching example.  You can install it on your server and run it to see the behavior.

1. The script will put up a form to accept your input (Line 115 - 135).  Give it the name, value and life of the cookie.
2. When the form is submitted, the action script will run (Line 1-111).  This will set the cookie, using the data from the form.
3. At this point the server has set the cookie.  In other words, the server has told the client browser to accept a cookie and return it on the next and subsequent calls from the client to the server.  The cookie will not be visible to the server until a new request arrives from the client.  And the cookie will only become visible to the server if the client accepts it and returns it.
4. You can click a link to see the current state of the cookies that were sent with this request.
5. If you create a cookie with a very short life (20 seconds, perhaps) you can click that link repeatedly to watch as the cookie expires.  The client browser will stop sending the cookie after its expiration.

Note that the part around line 60-63 works well for URLs like example.com, but may need some adjustment for URLs like example.com.fr.

Note also that some browsers may not accept cookies from localhost.  You may need to install this on an internet-based server to get it to work.

HTH, and please post back if you still have questions.

<?php // cookie_example.php

/**
 * THIS SCRIPT RECEIVES INPUT FROM AN HTML FORM AND SETS A COOKIE WITH THE NAME, VALUE AND LIFE FROM THE FORM
 *
 * MAN PAGE: http://php.net/manual/en/function.setcookie.php
 *
 * TO SEE COOKIES IN FIREFOX, FOLLOW SOMETHING LIKE THIS:
 * => TOOLS
 * => OPTIONS
 * => PRIVACY
 * => SHOW COOKIES
 */

error_reporting(E_ALL);

// IF THE FORM HAS BEEN POSTED
if (!empty($_POST))
{
    // TIDY UP THE POST INPUT - CLEAN AND NOT MORE THAN 16 BYTES
    $name = substr(clean_string($_POST["name"]),0,16);
    $data = substr(clean_string($_POST["data"]),0,16);
    $life = clean_number($_POST["life"]);

    // BE SURE WE HAVE USEFUL INFORMATION
    if ( ($name == '') || ($data == '') ) die("MISSING INPUT: PLEASE <a href=\"{$_SERVER['PHP_SELF']}\">TRY AGAIN</a>");


    // CHOOSE THE COOKIE NAME, VALUE, AND LIFE IN SECONDS
    $cookie_name    = $name;
    $cookie_value   = $data;
    $cookie_life    = $life;


    // CONFIGURE THE COOKIE LIFE
    if ($life <= 0)
    {
        // USE THIS TO MAKE COOKIE EXPIRE AT END OF BROWSER LIFE
        $cookie_expires = 0;
    }
    else
    {
        // USE THIS TO MAKE A PERSISTENT COOKIE
        $cookie_expires = time() + $cookie_life;
    }


    // MAKE THE COOKIE AVAILABLE TO ALL DIRECTORY PATHS
    $cookie_path	= DIRECTORY_SEPARATOR;


    // MAKE THE COOKIE AVAILABLE TO ALL SUBDOMAINS - DOMAIN NAME STARTS WITH DOT AND OMITS WWW (OR OTHER SUBDOMAINS).
    $x = explode('.', strtolower($_SERVER["HTTP_HOST"]));
    $y = count($x);
    if ($y == 1) // MAYBE 'localhost'?
    {
        $cookie_domain = $x[0];
    }
    else // SOMETHING LIKE 'www2.atf70.whitehouse.gov'?
    {
        // USE THE LAST TWO POSITIONS TO MAKE THE HOST DOMAIN
        $cookie_domain = '.' . $x[$y-2] . '.' . $x[$y-1];
    }


    // MAKE THE COOKIE AVAILABLE TO HTTP, NOT JUST HTTPS
    $cookie_secure    = FALSE;


    // HIDE COOKIE FROM JAVASCRIPT (PHP 5.2+)
    $cookie_http      = TRUE;


    // SET THE COOKIE
    if ( setcookie
    ( $cookie_name
    , $cookie_value
    , $cookie_expires
    , $cookie_path
    , $cookie_domain
    , $cookie_secure
    , $cookie_http
    )
    )
    {
        echo PHP_EOL . "<br/>SUCCESS!  THE COOKIE HAS BEEN SET AND WILL BE AVAILABLE TO THE NEXT PAGE LOAD";
    }
    else
    {
        echo PHP_EOL . "<br/>FAILURE!  THE COOKIE WAS NOT SET AS EXPECTED";
    }


    /**
     * AT THIS POINT, THE COOKIE HAS BEEN SET, BUT IT IS NOT AVAILABLE IN THIS SCRIPT
     * THE COOKIE WILL NOT BE RETURNED FROM THE CLIENT TO THE SERVER UNTIL THE NEXT HTTP REQUEST
     * THIS IS BECAUSE THE BROWSER SENDS THE COOKIE TO THE SERVER BEFORE OUR SCRIPT STARTS RUNNING
     */
    echo '<pre>';
    echo PHP_EOL . '$_COOKIE CONTAINS '; var_dump($_COOKIE);
    echo PHP_EOL . '$_POST CONTAINS ';   var_dump($_POST);
    echo PHP_EOL . 'THE COOKIE HAS BEEN SET WITH THESE VALUES: ';
    echo PHP_EOL . 'COOKIE NAME:    ' . $cookie_name;
    echo PHP_EOL . 'COOKIE VALUE:   ' . $cookie_value;
    echo PHP_EOL . 'COOKIE EXPIRES: ' . number_format($cookie_expires) . " == " . date('r', $cookie_expires);
    echo PHP_EOL . 'COOKIE PATH:    ' . $cookie_path;
    echo PHP_EOL . 'COOKIE DOMAIN:  ' . $cookie_domain;
    echo PHP_EOL . 'COOKIE SECURE:  '; var_dump($cookie_secure);
    echo           'COOKIE HTTP:    '; var_dump($cookie_http);
    echo "</pre>";
}


/**
 * END OF THE ACTION SCRIPT THAT SET THE COOKIE
 * CREATE THE HTML FORM, USING PHP HEREDOC NOTATION
 */
$self = $_SERVER["PHP_SELF"];
$form = <<<ENDFORM
<pre>
<form method="post">
COOKIE NAME: <input name="name" /> STRING
COOKIE DATA: <input name="data" /> STRING
COOKIE LIFE: <input name="life" /> INTEGER SECONDS
<input type="submit" />
<b>TO SEE THE EXISTING COOKIES <a href="$self">CLICK HERE</a></b>
</form>
</pre>
ENDFORM;
echo $form;


// SHOW THE COOKIE ARRAY, IF ANY
echo '<pre>$_COOKIE CONTAINS '; var_dump($_COOKIE); echo "</pre>";



// UNRELATED FUNCTIONS TO TIDY UP FORM INPUT
function clean_string($string)
{
    return trim(preg_replace('/[^A-Z0-9_]/i', NULL, $string));
}

function clean_number($string)
{
    return trim(preg_replace('/[^0-9-]/i',     0,    $string));
}

// ACTIVATE THIS TO SHOW THE SCRIPT CODE
// die( highlight_file(__FILE__, TRUE) );

Open in new window

0
 
LVL 2

Author Comment

by:hexo dark
ID: 40527734
i do not understand how to use it ?
0
 
LVL 57

Expert Comment

by:giltjr
ID: 40527745
Trying to read through all the updates.

It almost appears to me as if the PHP script is running on the client side trying to act like a browser instead of running on the server.

So hexo dark, is the script running as part of a service on a web server, or are you running this on a client?
0
 
LVL 2

Author Comment

by:hexo dark
ID: 40527752
running this on a client
0
 
LVL 57

Assisted Solution

by:giltjr
giltjr earned 125 total points
ID: 40527769
Ah, that could be the problem.  I was looking at this as if this was running on the server side.

Your script, as the client, should send all cookies back to the server on each request, but the server will only send back cookies if they have changed.  I do believe that somebody else pointed that out already.

Flow is:

You, the client, sends first HTTP request to the server.
The server responds with the cookie(s) set.
You send another anther request, including all cookies previously sent by the server.
The server will typically respond with NO cookie(s) because typically cookies don't change from one request to another.

I'll have to look at the script, but it should be saving the COOKIES as variables and reusing them or updating them as needed.
0
 
LVL 2

Author Comment

by:hexo dark
ID: 40528096
resolved

is this line the bug resolved
$old = $cookie;

Why this line crashed the script?
0
 
LVL 76

Accepted Solution

by:
arnold earned 250 total points
ID: 40528123
The script exits when the cookie provided in the new request (line 151) is the same cookie as the one received before and is compared on line 153.

$old=$cookie;
is a way to preserve the state.
i.e.
get(site)
$cookie is set.
before the script makes another request, it assigns the content of the current cookie to old.
$old=$cookie (preserving state of the current cookies)
now it makes a new request for video
get(site_ . video listing)
now it checks whether the $cookie is different than the last one.
When it is the same, the script stops working. (crashes) die 'error'

Comment out lines 153-156 and see if that fixes your script crash problem.
0
 
LVL 2

Author Closing Comment

by:hexo dark
ID: 40528150
nice job
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now