Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sinnbeck's avatar

Uhm. Your code does not make alot of sense.

Give this a go.

$csv=explode(",",$body);
        

            if (strpos($body, '<html>') !== false) 
            {
                 //Stay connected...
                                
                abort(500, 'Bad response');
             }


           foreach ($csv as $row)
       {
           $ApiData=str_getcsv($row);
       }
me10071990's avatar

why its showing error with my string if it was working fine , i don't know why this happing with my code

		syntax error, unexpected 'connected' (T_STRING)
Sinnbeck's avatar

Yes remove that text string.. Or comment it out. Look at my last example

me10071990's avatar

and it's aborting the whole website with 500 Server Error when using condition

	if (strpos($body, '<html>') === 0) 
        {
            
                            
            abort(500, 'Bad response');
         }

something strange with code

Sinnbeck's avatar

Yes bingo. that is what abort(500) means.. Throw an error 500.. Replace that with whatever you what to happen.. Like.. throw an exception.. Or return a view.. Or redirect...

me10071990's avatar

Yes, but why could not set the image or text with condition in controller, if i need 500 error for a small place then it should be used in there only, can change abort(500, 'Bad response'); to like text or image without redirect or return review?

Sinnbeck's avatar

You need to return something.. Perhaps make a page to go to when it fails, and redirect to that?

Previous

Please or to participate in this conversation.