session_start() [function.session-start]:

 更新时间:2016年11月25日 15:59  点击:2045

我在学习PHP的,当我尝试做在session_start() - 获取有关错误信息不能发送会话cookie。

我看到在这个问题上前面的问题,但是,仍然不能确定我的错误。

如果是错误家伙?
<?php
session_start();
      if ($_POST['add'])
      {
            foreach ($_POST['a_qty'] as $k => $v)
            {
                  $_SESSION['cart'][$k] = $_SESSION['cart'][$k] + $v;
            }
      }
?>
<?php
// look for catalog file
      $catalogfile = "catalog.dat";
      // file is avaialbe, extract data from it and place into $catalog, with sku as key
      if (file_exists($catalogfile))
      {
            $data = file($catalogfile);
            foreach ($data as $line)
            {
                  $lineArray = explode(":", $line);
                  $sku = trim($lineArray[0]);
                  $CATALOG[$sku]['desc'] = trim($lineArray[1]);
                  $CATALOG[$sku]['price'] = trim($lineArray[2]);                             
            }
      }
      else
      {
            die("Could not find the catalog file");
      }
?>
<table border="1" cellspacing="10">
<?php
            // print items from the catalog for selection
            foreach ($CATALOG as $k => $v)
            {
                  echo "<tr><td colspan=2 width=750>";
                  echo "<b>" . $v['desc'] . "</b>";
                  echo "</td></tr>";
                  echo "<tr><td>";
                  echo "Price per unit: " . $CATALOG[$k]['price'];
                  echo "</td><td>Quantity: ";
                  echo "<input size=4 type=text name="a_qty[" . $k . "]">";
                  echo "</td></tr> ";
            }
?>

<?php
/*** an array of attributes about a dog ***/
$array = array('animal'=>'dog', 'name'=>'Offenbach', 'owner'=>'Mr Smith');

/*** add the dogs favourite food to the array ***/
$array = ($array, 'food', 'postmans leg');

/*** print the array ***/
print_r($array);

/**
 * @Push and element onto the end of an array with associative key
 *
 * @param array $array
 *
 * @string $key
 *
 * @mixed $value
 *
 * @return array
 *
 */
function ($array, $key, $value){
 $array[$key] = $value;
 return $array;
}

?>

This will return the following results

Array
(
   [animal] => dog
   [name] => Offenbach
   [owner] => Mr Smith
   [food] => postmans leg
)

 

<?php

function xmlStringToArray($xmlString)
        {
        $xmlString = preg_replace('/<!--.*?-->/s','',$xmlString);
        $exitAfterManyLoops = 0;
        $xmlArray = array();
        $currentNode = &$xmlArray;
        $currentHierarchy = array();
        $currentDepth = 0;
        while($xmlString != '')
                {
                $exitAfterManyLoops++;
                if($exitAfterManyLoops > 300)
                        {
                        print "BREAK";
                        break;
                        }
                $xmlString = trim(substr($xmlString, strpos($xmlString, '<')));
                $thisNodeAscends = (substr($xmlString, 1, 1) == '/');
                $thisNodeDescends = (substr($xmlString, strpos($xmlString, '>') - 1, 1) != '/');
                $nodeName = substr($xmlString, 1, strpos($xmlString, ' ') -1);
                $openElement = substr($xmlString, strpos($xmlString, ' ') + 1);
                $openElement = substr($openElement, 0, strpos($openElement, '>') );
                if(substr($openElement, strlen($openElement) - 1, 1) == "/")
                        {
                        $openElement = substr($openElement, 0, strlen($openElement) - 1);
                        }

                if($thisNodeAscends)
                        {
                        $currentDepth--;
                        $currentNode = &$currentHierarchy[$currentDepth];
                        }
                else
                        {
                        if($thisNodeDescends)
                                {
                                $currentNode[] = array('__attributes' => parseXmlAttributesString($openElement), '__children' => array(), '__nodeName' => $nodeName);
                                $currentHierarchy[$currentDepth] = &$currentNode;
                                $currentDepth++;
                                $lastItem = &$currentNode[count($currentNode) - 1];
                                $currentNode = &$lastItem['__children'];
                                }
                        else //this node is at the same level
                                {
                                $currentNode[] = array('__attributes' => parseXmlAttributesString($openElement), '__nodeName' => $nodeName);
                                }

                        }
                $xmlString = substr($xmlString, strpos($xmlString, '>') + 1);
                }
        return $xmlArray;
        }

 

function parseXmlAttributesString($xmlElementString)
        {
        $exitAfter100Loops = 0;
        $xmlElementArray = array();
        while($xmlElementString != '')
                {
                $exitAfter100Loops++;
                if($exitAfter100Loops > 100)
                        {
                        print "BREAK";
                        break;
                        }
                $equalsCharacterPos = strpos($xmlElementString, '=');
                $key = trim(substr($xmlElementString, 0, $equalsCharacterPos));
                $xmlElementString = substr($xmlElementString, $equalsCharacterPos + 1);
                $openBracket = substr($xmlElementString, 0, 1);
                $xmlElementString = substr($xmlElementString, 1);
                $endBracketPos = strpos($xmlElementString, $openBracket);
                $value = substr($xmlElementString, 0, $endBracketPos);
                $xmlElementString = substr($xmlElementString, $endBracketPos + 1);
                if($key)
                        {
                        $xmlElementArray[$key]=$value;
                        }
                }
        return $xmlElementArray;
        }

?>

<?php

function copyViaFtpRecursively($uploadLocation, $previewPath, $remoteDirectory, $ftpType)
        {
        $errorMessage = '';

        $connectionId = getFtpConnection($uploadLocation['host'], $uploadLocation['username'], $uploadLocation['password'], $uploadLocation['port']);
        switch($ftpType)
                {
                case 'active':
                        ftp_pasv($connectionId, False);
                        break;
                case 'passive':
                        ftp_pasv($connectionId, True);
                        break;
                }

        $baseDirectory = $uploadLocation['baseDirectory'];
        if(substr($baseDirectory, strlen($baseDirectory) - 1, 1) != '/')
                {
                $baseDirectory .= '/';
                }
        ftp_mkdir($connectionId, $baseDirectory); // No point showing an error message if the directory exists (most likely cause of error) because it will exist (at least) after the first time.

        $remoteBaseDirectory = $baseDirectory.$remoteDirectory;
        if(substr($remoteBaseDirectory, strlen($remoteBaseDirectory) - 1, 1) == '/')
                {
                $remoteBaseDirectory = substr($remoteBaseDirectory, 0, strlen($remoteBaseDirectory) - 1);
                }

        $remoteBaseDirectory .= '/';
        $errorMessage .= copyFileViaFtp($previewPath, $remoteBaseDirectory, $connectionId);

        ftp_close($connectionId);

        $errorHtml = '';
        if($errorMessage)
                {
                $errorHtml = nl2br($errorMessage);
                }
        return $errorHtml;
        }

function getFtpConnection($host, $username, $password, $port)
        {
        $connectionId = ftp_connect($host);
        if(!@ftp_login($connectionId, $username, $password))
                {
                webServiceError('FTP error. Unable to connect to "'.$host.'" with username "'.$username.'"');
                }
        return $connectionId;
        }


function copyFileViaFtp($sourcePath, $destinationPath, $connectionId)
        {
        $errorMessage = '';
        $sourcePath = str_replace(" ", "-", $sourcePath);
        $destinationPath = str_replace(" ", "-", $destinationPath);
        if(!ftp_mkdir($connectionId, $destinationPath))
                {
                $errorMessage .= "Unable to create directory at ".$destinationPath." (it may already exist) ";
                }
        ftp_site($connectionId, 'CHMOD 0777 '.$destinationPath);
        ftp_chdir($connectionId, $destinationPath);
        //print $sourcePath.' to '.$destinationPath."<br />";
        if(is_dir($sourcePath))
                {
                chdir($sourcePath);
                $handle=opendir('.');
                while(($file = readdir($handle))!==false)
                        {
                        if(($file != ".") && ($file != ".."))
                                {
                                if(is_dir($file))
                                        {
                                        $errorMessage .= copyFileViaFtp($sourcePath.DIRECTORY_SEPARATOR.$file, $file, $connectionId);
                                        chdir($sourcePath);
                                        if(!ftp_cdup($connectionId))
                                                {
                                                $errorMessage .= "Unable to ftp_cdup. ";
                                                }
                                        }
                                else
                                        {
                                        if(substr($file, strlen($file) - 4, 4) != ".zip")
                                                {
                                                $fp = fopen($file,"r");
                                                if(!ftp_fput($connectionId, str_replace(" ", "_", $file), $fp, FTP_BINARY))
                                                        {
                                                        $errorMessage .= "Unable to ftp_fput(). ";
                                                        }
                                                ftp_site($connectionId, 'CHMOD 0755 '.str_replace(" ", "_", $file));
                                                }
                                        }
                                }
                        }
                closedir($handle);
                }

        return $errorMessage;
        }

 代码如下 复制代码

function _link($url){
 $contents = @file_get_contents("$url");
 if($contents=="Forbidden" || $contents==""){
  $ch = curl_init();
  $timeout = 5;
  curl_setopt ($ch, CURLOPT_URL, "$url");
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $contents = curl_exec($ch);
  curl_close($ch);
 }
 if(empty($contents)){
  exit('<font color=red>cant locaion.</font>');
 }
 preg_match_all("/charset=(.*?)>/is",$contents,$cod);
 if(!empty($cod[1][0])){
  if(preg_match("/utf-8/i",$cod[1][0])){
   $contents=iconv("UTF-8","gbk//TRANSLIT",$contents);
  }
 }
 return $contents;
}

[!--infotagslink--]

相关文章

  • PHP session_start()很慢问题分析与解决办法

    本文章来给各位同学介绍一下关于PHP session_start()很慢问题分析与解决办法,希望碰到此问题的同学可进入参考。 最近在做东西的时候发现一个问题 有一个接口挂...2016-11-25
  • PHP分布式框架如何使用Memcache同步SESSION教程

    本教程主要讲解PHP项目如何用实现memcache分布式,配置使用memcache存储session数据,以及memcache的SESSION数据如何同步。 至于Memcache的安装配置,我们就不讲了,以前...2016-11-25
  • 详解C#中的session用法

    这篇文章主要介绍了C#中的session用法 ,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • Python3使用Selenium获取session和token方法详解

    这篇文章主要介绍了Python3使用Selenium获取session和token方法详解,需要的朋友可以参考下...2021-02-17
  • Pytorch 的损失函数Loss function使用详解

    今天小编就为大家分享一篇Pytorch 的损失函数Loss function使用详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-05-02
  • 编程新手必须掌握的:session与cookie的区别

    session和cookie是网站浏览中较为常见的两个概念,也是比较难以辨析的两个概念,但它们在点击流及基于用户浏览行为的网站分析中却相当关键。基于网上一些文章和资料的参阅,及作者个人的应用体会,对这两个概念做一个简单的阐述...2013-09-11
  • PHP中如何使用session实现保存用户登录信息

    session在php中是一个非常重要的东西,像我们用户登录一般都使用到session这个东西,相对于cookie来说session 要安全很多,同时我们购物车经常使用session来做临时的记录保存哦。使用session保存页面登录信息1、数据库连接...2015-10-21
  • Vue使用axios引起的后台session不同操作

    这篇文章主要介绍了Vue使用axios引起的后台session不同操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-08-14
  • php中session常见问题分析

    PHP的session功能,一直为许多的初学者为难。就连有些老手,有时都被搞得莫名其妙。本文,将这些问题,做一个简单的汇总,以便大家查阅。 1. 错误提示 引用 代...2016-11-25
  • php设置session生存时间详解

    要设置php生存有效时间我们可以利用session_set_cookie_params函数或修改php.ini文件哦,下面小编来介绍一下。 第一种方法:session_set_cookie_params 函数原型 voi...2016-11-25
  • jQuery ajax全局函数处理session过期后的ajax跳转问题

    这篇文章主要介绍了基于jQuery的全局ajax函数处理session过期后的ajax操作的相关资料,需要的朋友可以参考下...2016-06-12
  • jsp使用sessionScope获取session案例详解

    这篇文章主要介绍了jsp使用sessionScope获取session案例详解,本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下...2021-08-29
  • php提示 Warning: touch() [function.touch]: Utime failed: Permission denied in错误

    在使用php程序时提示Warning: touch() [function.touch]: Utime failed: Permission denied in错误,下面一起来看看此问题的解决办法。 使用timthumb.php出现Warni...2016-11-25
  • C#实现简单获取及设置Session类

    这篇文章主要介绍了C#实现简单获取及设置Session类,涉及C#针对session的设置及获取的技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • Warning: mssql_connect() [function.mssql-connect]:

    我是这样做的,确定mssql是正常的用户名密码也可以,但下面就是不行。 <?php教程 $con=mssql_connect( "localhost", "sa ", "123456 ") or die ('error'); ?>...2016-11-25
  • asp.net中穿透Session 0 隔离(二)

    上一篇我们已经对Session 0 隔离有了进一步认识,如果在开发过程中确实需要服务与桌面用户进行交互,可以通过远程桌面服务的API 绕过Session 0 的隔离完成交互操作...2021-09-22
  • Node.js刷新session过期时间的实现方法推荐

    下面小编就为大家带来一篇Node.js刷新session过期时间的实现方法推荐。小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2016-05-20
  • Java8通过Function获取字段名的方法(获取实体类的字段名称)

    Java8通过Function获取字段名。不用再硬编码,效果类似于mybatis-plus的LambdaQueryWrapper,对Java8通过Function获取字段名相关知识感兴趣的朋友一起看看吧...2021-09-29
  • php CURLOPT错误Warning: curl_setopt() [function.curl-setopt]:...

    在我们使用php curl函数时提示Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir...2016-11-25
  • PHP session并发及session读写锁分析

    关于PHP session并发及session读写锁问题估计各大程序员都不会想到这个问题,因为一般情况我们不会使用session来做并发操作了,但有时也有可能用到,下面整理一个session并...2016-11-25