I want to file_get_contents and login at . That was the easy part, now since i am logged in i want to file_get_contents at , but i don't get  the results i was expecting. That is, not loose the session between the 2 file_get_contents. Instead the second file_get_contents result in the  which broke my heart. Here is my code: &lt;?php $url_login = 'http://example.com/test/index.php';  $postdata = http_build_query(     array(         'username' =&gt; 'user1',         'password' =&gt; '123',         'login' =&gt; 'true'     ) );  $opts = array('http' =&gt;     array(         'method'  =&gt; 'POST',         'header'  =&gt; 'Content-Type: application/x-www-form-urlencoded',         'content' =&gt; $postdata     ) );  $context  = stream_context_create($opts);  $result = file_get_contents($url_login, false, $context); echo $result;  //--So far ok, $result shows me that i am logged in--//  // Now that i am logged in i want to access the member_area.php. $url_member_area = 'http://example.com/member_area.php';  $result = file_get_contents( $url_member_area, false, $context);     echo $result; ?&gt;  i must achieve that using file_get_contents and not cUrl. I think it has to do with session, but i have no idea where and how to implement. Thanks in advance, i buy you a Beer! UPDATED CODE: &lt;?php $url_login = 'http://example.com/test/index.php';  $postdata = http_build_query(     array(         'username' =&gt; 'user1',         'password' =&gt; '123',         'login' =&gt; 'true'     ) );  $opts = array('http' =&gt;     array(         'method'  =&gt; 'POST',         'header'  =&gt; 'Content-Type: application/x-www-form-urlencoded',         'content' =&gt; $postdata     ) );  $context  = stream_context_create($opts);  $result = file_get_contents($url_login, false, $context); echo $result;  //--So far ok, $result shows me that i am logged in--// $url_member_area = 'http://example.com/member_area.php'; // Create a stream $opts = array(   'http'=&gt;array(     'method'=&gt;&quot;GET&quot;,     'header'=&gt;&quot;Accept-language: en\r\n&quot; .               &quot;Cookie: username=user1;password=123;login=true&quot;   ) );  $context = stream_context_create($opts);  // Open the file using the HTTP headers set above $file = file_get_contents($url_member_area, false, $context); // Now that i am logged in i want to access the member_area.php.       echo $file;  Brings me back to index.php asking me to log in, i was hoping to get the member_area.php.  Offer Updated to 2 Beers *People, i ask for a recipe on how to make Apple pie, you link me to a page on how to wash the apples, and stackoverflow tells me that my question has been answered. Thanks anyway :D
45119
I'm trying to get the contents from another file with file_get_contents (don't ask why). I have two files: test1.php and test2.php. test1.php returns a string, bases on the user that is logged in. test2.php tries to get the contents of test1.php and is being executed by the browser, thus getting the cookies. To send the cookies with file_get_contents, I create a streaming context: $opts = array('http' =&gt; array('header'=&gt; 'Cookie: ' . $_SERVER['HTTP_COOKIE'].&quot;\r\n&quot;))`;  I'm retrieving the contents with: $contents = file_get_contents(&quot;http://www.example.com/test1.php&quot;, false, $opts);  But now I get the error:  Warning: file_get_contents() [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found  Does somebody knows what I'm doing wrong here? edit: forgot to mention: Without the streaming_context, the page just loads. But without the cookies I don't get the info I need.
26532
I'm trying to write a page that calls PHP that's stored in a MySQL database. The page that is stored in the MySQL database contains PHP (and HTML) code which I want to run on page load.  How could I go about doing this?
63718
I'm trying to use PHP's CURL function to fetch geoJSON information from a GeoServer instance. I'm doing this using url variables rather than trying to construct a full xml GetFeature request.  However, I would like to be able to get a subset of the results based on some of the property fields' contents.  So, while I can get all of the results using this url:    can I also limit the results to "Where field LIKE value" or "field = value"?  I've spent an hour trawling through the Geoserver/ECQL documentation and none of it clearly states "append the functions to your URL in this format". As a result, I'm not clear if it's possible to use url variables to perform these tasks, but some people seem to suggest that it is.  Can anyone help with a clear example of a working filter using GeoServer's WFS with URL parameters?
37551
I want to load the new entries without reloading the page. I found a great solution for: The ajax script:  &lt;script&gt;     $(document).ready(function() {     var refreshId = setInterval(function()     {         $('#content').fadeOut("fast").load('http://neocsatblog.mblx.hu/new.php').fadeIn("fast");     }, 10000);      }); &lt;/script&gt;   And the php:  &lt;?php require_once("wp-blog-header.php"); ?&gt; &lt;div id="content" &lt;?php cyberchimps_filter_content_class(); ?&gt;&gt;          &lt;?php do_action( 'cyberchimps_before_content'); ?&gt;          &lt;?php if ( have_posts() ) : ?&gt;              &lt;?php while ( have_posts() ) : the_post(); ?&gt;                  &lt;?php get_template_part( 'content', get_post_format() ); ?&gt;              &lt;?php endwhile; ?&gt;          &lt;?php elseif ( current_user_can( 'edit_posts' ) ) : ?&gt;              &lt;?php get_template_part( 'no-results', 'index' ); ?&gt;          &lt;?php endif; ?&gt;          &lt;?php do_action( 'cyberchimps_after_content'); ?&gt;      &lt;/div&gt;   However, this is a special feature that works perfectly here:  However, the main page refuses to load new entries, I do not understand the reason for this, as we use everything the same.
85415
I want to show a custom block, only when log in has failed. So from visibility settings I have to put a PHP code that returns TRUE only when the login has failed.  But how could I "catch" that event? Do I have to use variable_get(..)? And if yes, how could I use that?with what attributes?  Thank you.
40564
I'm retrieving a gzipped web page via curl, but when I output the retrieved content to the browser I just get the raw gzipped data. How can I decode the data in PHP?  One method I found was to write the content to a tmp file and then ...  $f = gzopen($filename,"r"); $content = gzread($filename,250000); gzclose($f);   .... but man, there's got to be a better way.  Edit: This isn't a file, but a gzipped html page returned by a web server.
13403
I have a tiny script that simply fetches the current date, runs a PHP script and redirect the output (and errors) to a filename containing the current date.  DATE=$(date +"%Y%m%d") FILE="log/${DATE}.log" php -q script.php &gt;&gt; $FILE 2&gt;&amp;1   When I run this script on my local machine (Windows 7, Aptana IDE), the PHP script works fine and the logfile has the expected filename, e.g. 20140502.log.  But when I push that script via SFTP to my remote machine and execute that script, the filename looks like this:  20140502?.log?   What might be the problem? Is this an enconding error (e.g. encoding for SFTP uploads is ANSII, where UTF-8 is expected)? Or do I have to change anything in the script itself?  Information about system/shell:  [foo@bar path]$ sh --version GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)   Funny fact: If that script is called by a cronjob, the question marks don't occur. Only if I manually run the script.
100808
I have a PHP application that will on occasion have to handle URLs where more than one parameter in the URL will have the same name. Is there an easy way to retrieve all the values for a given key? PHP $_GET returns only the last value.   To make this concrete, my application is an OpenURL resolver, and may get URL parameters like this:  ctx_ver=Z39.88-2004 &amp;rft_id=info:oclcnum/1903126 &amp;rft_id=http://www.biodiversitylibrary.org/bibliography/4323 &amp;rft_val_fmt=info:ofi/fmt:kev:mtx:book &amp;rft.genre=book &amp;rft.btitle=At last: a Christmas in the West Indies.  &amp;rft.place=London, &amp;rft.pub=Macmillan and co., &amp;rft.aufirst=Charles &amp;rft.aulast=Kingsley &amp;rft.au=Kingsley, Charles, &amp;rft.pages=1-352 &amp;rft.tpages=352 &amp;rft.date=1871   (Yes, I know it's ugly, welcome to my world). Note that the key "rft_id" appears twice:   rft_id=info:oclcnum/1903126 rft_id=http://www.biodiversitylibrary.org/bibliography/4323   $_GET will return just http://www.biodiversitylibrary.org/bibliography/4323, the earlier value (info:oclcnum/1903126) having been overwritten.  I'd like to get access to both values. Is this possible in PHP? If not, any thoughts on how to handle this problem?
114332
I have the problem, that PHP replaces all spaces with underscores in POST and GET variables. For example if I have the URL: http://localhost/proxy.php?user name=Max the browser will convert it to http://localhost/proxy.php?user%20name=Max. But if I give the $_GET parameters out, the key is not user name but user_name (note the underscore)! Is there any possibility to change this behaviour?
20950
I would like to redirect users after they log in. Is it possible to use hook_user_login() to make the redirection? How do I add the parameter for the redirection?
76790
I've looked at dozens of other questions and references on the web - and by all my calculations, my setup should work, but it doesn't.  I have nginx installation with php-fpm.  If I try to access a .php file, it runs correctly and I get the correct results.  I got this in my config file:  location ~ \.php$ {     try_files $uri =404;     fastcgi_pass unix:/var/run/php5-fpm.sock;     include fastcgi_params;     fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name; }   Now, I want to setup my web app so that /somedir/file automatically executes /somdir/file.php while still displaying /somdir/file in the browser's address bar.  So I modified my config to contain the following:  location / {     try_files $uri $uri/ $uri.php?query_string }   This kind of works, that is, the server does access the .php file.  Yet, instead of executing it using the existing location ~ \.php$ block above, it simply spits the php source code as the download into the browser.  If I append the .php manually to the requested URL, then the php is executed.  It feels as if once the server matches try_files to $uri.php, it then does not do another pass at locations to see that what it needs to do with the php files.  I tried putting the php block above and below the location /, but it makes no difference.  How can I get the php to be executed?
33938
I have one of those "I swear I didn't touch the server" situations. I honestly didn't touch any of the php scripts. The problem I am having is that php data is not being saved across different pages or page refreshes. I know a new session is being created correctly because I can set a session variable (e.g. $_SESSION['foo'] = "foo" and print it back out on the same page just fine. But when I try to use that same variable on another page it is not set! Is there any php functions or information I can use on my hosts server to see what is going on?  Here is an example script that does not work on my hosts' server as of right now:  &lt;?php session_start(); if(isset($_SESSION['views']))     $_SESSION['views'] = $_SESSION['views']+ 1; else     $_SESSION['views'] = 1;  echo "views = ". $_SESSION['views']; echo '&lt;p&gt;&lt;a href="page1.php"&gt;Refresh&lt;/a&gt;&lt;/p&gt;'; ?&gt;   The 'views' variable never gets incremented after doing a page refresh. I'm thinking this is a  problem on their side, but I wanted to make sure I'm not a complete idiot first.  Here is the phpinfo() for my hosts' server (PHP Version 4.4.7):
61270
if (strstr($_SERVER['REQUEST_URI'],'index.php')) {     header('HTTP/1.0 404 Not Found'); }   Why wont this work? I get a blank page.
1953
What is the best way to password protect quicktime streaming videos using php/.htaccess. They are being streamed using rtsp, but I can use other formats if necessary.  I know how to do authentication with php, but I'm not sure how to setup authentication so that will protect the streaming files urls so that a user can't just copy the url and share it.  Or am I overthinking this and I can just use a normal authentication scheme and place the files in a protected directory?
123476
I've script as below :- (edited)  httpUrl="http://www.nnin.com" rep=$(curl -v -X POST -d "UID=username&amp;PWD=pass" $httpUrl)  status=$?   if [ "$?" -eq 0 ]; then      echo "Success"     exit $status   else     echo "Failed"     exit $status fi   when I run the script the return code always $?=0 because in a way the script is successfully execute but I want the return code for cURL to apply in next function.  I've try browsing around and use several method in this site particularly but doesn't help much, maybe because of the POST command and how to prevent the output from print when I run the script?  Thanks
91776
I have created a shortcode that retrives and displays a form.The content of the attribute in HTML.   function check_my_login( $atts)     {          return '&lt;form action="" name="" method="post" enctype="multipart/form-data"&gt;                &lt;div class="form-group"&gt;                     &lt;label for="description"&gt;Project Description&lt;/label&gt;                     &lt;textarea name="p_description" placeholder="Project Description" class="form-control"&gt;&lt;?php if (isset($_POST['p_description']) &amp;&amp; $_POST['p_description'] != '') echo $_POST['p_description'] ?&gt;&lt;/textarea&gt;                 &lt;/div&gt;                  &lt;div class="form-group"&gt;                     &lt;label&gt;Project Attachment&lt;/label&gt;                     &lt;input type="file" name="p_attachment"&gt;                 &lt;/div&gt; &lt;/form&gt;';     }     add_shortcode( 'kentaUser', 'check_my_login' );   Now use this shortcode inside the Post/page.   Like this    &lt;div class='manage_page'&gt;[kentaUser]&lt;/div&gt;  But my shortcode content display out side the div.Display upper side in post/page content.  &lt;div class='manage_page'&gt;&lt;/div&gt;    Any one short out this problem.
91306
I hope someone is able to help me. The problem is the following one: 1)I have module in which a assign the variable in order to send to the template file php.tpl  &lt;?php ... $testvar="Hello from alex!"; $variables['testvar'] = $testvar;  ... ?&gt;   This variable can be shown in the php.tpl file like   &lt;?php print $testvar?&gt;   2)I have separated .js file How can i get access to this varuiable inside .js file?  I know how it'll be if .js file is inside .php.tpl:  &lt;?php $testvar="Hello from alex!"; ?&gt; &lt;script type="text/javascript"&gt; var myVar = '&lt;?php print $testvar?&gt;'; &lt;/script&gt;   The problem is how to do the same if these two files .js and .php.tpl are separated?