PHP - I'm Seriously A Php Noob...3 Problems. Long Read. Makes No Sense. Php Driving Me Nuts.
Hi everyone. I'm completely new to PHP. I've been trying to teach myself to code with it and learn as much as I can for the past few days because it'll definitely come in handy. So far, everything I've learned is just from articles and videos.
Anyway, let's skip the boring stuff.
For literally the whole day today, I've been trying to figure out what the heck is wrong with a script I'm working with. I didn't code it myself. I'm pretty much just modifying it to fit my needs from the generic "template" it comes in.
So here's the issue:
The script is basically used to run a website with user generated content. Users can upload images and write about them. One file of the script deals with the page where the user writes and submits his/her content. Before, I had no issues. I could write a title, a few sentences, upload an image and submit it to the server. Now, seemingly out of nowhere, I'm getting problems everywhere.
Here are the issues:
1. After I fill out the form and hit submit, the page doesn't redirect to my content.
2. As soon as I hit the submit button, the page goes blank (white screen) and gets stuck on mydomain.com/submit (which is the same page where I filled out the form)
3. Along with the white screen, I'm getting the following error on top of it:
Notice: Undefined index: name in .../public_html/include/p-page-ask.php on line 126
I've spent the last 12 hours trying to fix this. For issue 3, I've read that you can use the "isset" function to fix it. But I have no idea how to code that into it. I tried different variations, but none worked to make it go away. For issue 2, I'm guessing this is a fatal php error? I have no idea what's causing it. If I view source, I just get a blank page. For issue 1, I'm guessing this has to do with issue 2 halting the page from redirecting? I'm pretty sure 2 and 3 are different errors because I've read that even if 3 occurs, the page still loads.
I've turned on all the error reporting and display functions in my php.ini file. I made sure that the server is using that particular file with phpinfo(). (Although I didn't restart my server. I have no idea how to. I'm on a shared environment). After making these changes, I still don't see any additional errors, just the notice on a blank page.
I've looked through the code for syntax errors, but couldn't find any.
I've even installed xampp and made a test environment. I read through the documentation and watched tutorials on YouTube to set it up. (I've had absolutely 0 experience with this kind of stuff). I downloaded all the exact files from my online server into my localhost environment. Funny enough, it works just fine on my machine. It doesn't even throw errors locally. However, it doesn't work online. What the heck is going on?
The only differences I can think of between the two environments are the php versions and sql database versions (xampp is newer)...but I don't know if that really makes a difference because the script USED to work on my server, so it must be compatible with the set versions.
I've been editing the files in the script for quite a while now. I know when I first started, the uploads would work just fine. Then I didn't upload for a while because I already tested it out and knew it worked, so I just continued working on the script. I may have modified something that's now causing the errors. But then wouldn't that cause the localhost environment to fail too? If the files are exactly the same, how could one fail to work? That makes no sense at all. I'm looking at this code lost and hopeless. I'm getting sad.
If ANYONE has any suggestions on fixing this, PLEASE let me know. I don't know what to do anymore.
If you need me to upload any of the other files, just ask.
Here are the error logs from the server:
PHP Notice: Undefined index: name in .../public_html/include/p-page-ask.php on line 126, referer:mydomain.com/submit
...public_html/submit: No such file or directory
WARNING: .../public_html/submit: Can't access file Here's the code for the page with the notice: <?php if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser header('Location: ../'); exit; } require_once QA_INCLUDE_DIR.'p-app-format.php'; require_once QA_INCLUDE_DIR.'p-app-limits.php'; require_once QA_INCLUDE_DIR.'p-db-selects.php'; require_once QA_INCLUDE_DIR.'p-util-sort.php'; // Check whether this is a follow-on question and get some info we need from the database $in=array(); $followpostid=qa_get('follow'); $in['categoryid']=qa_get_category_field_value('category'); if (!isset($in['categoryid'])) $in['categoryid']=qa_get('cat'); $userid=qa_get_logged_in_userid(); list($categories, $followanswer, $completetags)=qa_db_select_with_pending( qa_db_category_nav_selectspec($in['categoryid'], true), isset($followpostid) ? qa_db_full_post_selectspec($userid, $followpostid) : null, qa_db_popular_tags_selectspec(0, QA_DB_RETRIEVE_COMPLETE_TAGS) ); if (!isset($categories[$in['categoryid']])) $in['categoryid']=null; if (@$followanswer['basetype']!='A') $followanswer=null; // Check for permission error $permiterror=qa_user_maximum_permit_error('permit_post_q', QA_LIMIT_QUESTIONS); if ($permiterror) { $qa_content=qa_content_prepare(); // The 'approve', 'login', 'confirm', 'limit', 'userblock', 'ipblock' permission errors are reported to the user here // The other option ('level') prevents the menu option being shown, in qa_content_prepare(...) switch ($permiterror) { case 'login': $qa_content['error']=qa_insert_login_links(qa_lang_html('question/ask_must_login'), qa_request(), isset($followpostid) ? array('follow' => $followpostid) : null); break; case 'confirm': $qa_content['error']=qa_insert_login_links(qa_lang_html('question/ask_must_confirm'), qa_request(), isset($followpostid) ? array('follow' => $followpostid) : null); break; case 'limit': $qa_content['error']=qa_lang_html('question/ask_limit'); break; case 'approve': $qa_content['error']=qa_lang_html('question/ask_must_be_approved'); break; default: $qa_content['error']=qa_lang_html('users/no_permission'); break; } return $qa_content; } // Process input $captchareason=qa_user_captcha_reason(); $in['title']=qa_post_text('title'); // allow title and tags to be posted by an external form $in['extra']=qa_opt('extra_field_active') ? qa_post_text('extra') : null; $in['tags']=qa_get_tags_field_value('tags'); if (qa_clicked('doask')) { require_once QA_INCLUDE_DIR.'p-app-post-create.php'; require_once QA_INCLUDE_DIR.'p-util-string.php'; $categoryids=array_keys(qa_category_path($categories, @$in['categoryid'])); $userlevel=qa_user_level_for_categories($categoryids); $in['notify']=qa_post_text('notify') ? true : false; $in['email']=qa_post_text('email'); $in['queued']=qa_user_moderation_reason($userlevel) ? true : false; qa_get_post_content('editor', 'content', $in['editor'], $in['content'], $in['format'], $in['text']); $errors=array(); if (!qa_check_form_security_code('ask', qa_post_text('code'))) $errors['page']=qa_lang_html('misc/form_security_again'); else { $filtermodules=qa_load_modules_with('filter', 'filter_question'); foreach ($filtermodules as $filtermodule) { $oldin=$in; $filtermodule->filter_question($in, $errors, null); qa_update_post_text($in, $oldin); } if (qa_using_categories() && count($categories) && (!qa_opt('allow_no_category')) && !isset($in['categoryid'])) $errors['categoryid']=qa_lang_html('question/category_required'); // check this here because we need to know count($categories) elseif (qa_user_permit_error('permit_post_q', null, $userlevel)) $errors['categoryid']=qa_lang_html('question/category_ask_not_allowed'); if ($captchareason) { require_once 'p-app-captcha.php'; qa_captcha_validate_post($errors); } if (empty($errors)) { $cookieid=isset($userid) ? qa_cookie_get() : qa_cookie_get_create(); // create a new cookie if necessary $questionid=qa_question_create($followanswer, $userid, qa_get_logged_in_handle(), $cookieid, $in['title'], $in['content'], $in['format'], $in['text'], qa_tags_to_tagstring($in['tags']), $in['notify'], $in['email'], $in['categoryid'], $in['extra'], $in['queued'], $in['name']); qa_redirect(qa_q_request($questionid, $in['title'])); // our work is done here } } } // Prepare content for theme $qa_content=qa_content_prepare(false, array_keys(qa_category_path($categories, @$in['categoryid']))); $qa_content['title']=qa_lang_html(isset($followanswer) ? 'question/ask_follow_title' : 'question/ask_title'); $qa_content['error']=@$errors['page']; $editorname=isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_qs'); $editor=qa_load_editor(@$in['content'], @$in['format'], $editorname); $field=qa_editor_load_field($editor, $qa_content, @$in['content'], @$in['format'], 'content', 12, false); $field['label']=qa_lang_html('question/q_content_label'); $field['error']=qa_html(@$errors['content']); $custom=qa_opt('show_custom_ask') ? trim(qa_opt('custom_ask')) : ''; $qa_content['form']=array( 'tags' => 'name="ask" method="post" action="'.qa_self_html().'"', 'style' => 'tall', 'fields' => array( 'custom' => array( 'type' => 'custom', 'note' => $custom, ), 'title' => array( 'label' => qa_lang_html('question/q_title_label'), 'tags' => 'name="title" id="title" autocomplete="off"', 'value' => qa_html(@$in['title']), 'error' => qa_html(@$errors['title']), ), 'similar' => array( 'type' => 'custom', 'html' => '<span id="similar"></span>', ), 'content' => array( 'tags' => 'name="content" id="content" autocomplete="off" class="hide"', 'value' => qa_html(@$in['content']), 'error' => qa_html(@$errors['content']), ), 'imgupload' => array( 'type' => 'custom', 'html' => '<label class="imguploadbtn" for="checkbox-menu3">Upload image</label>', ), 'imgprev' => array( 'type' => 'custom', 'html' => '<div class="imgprev"><img id="imgprev" />or</div>', ), 'imgurl' => array( 'type' => 'custom', 'html' => '<input id="imgurl" placeholder="image url" type="text" autocomplete="off" ><input type="checkbox" name="check1" id="imgurlc" class="hide" onclick="copyTextValue();"/> <label class="imgurlb" for="imgurlc">Add</label><script>$("#imgurl").on({ keydown: function(e) { if (e.which === 32) return false; }, change: function() { this.value = this.value.replace(/\s/g, ""); } });</script>', ), ), 'buttons' => array( 'ask' => array( 'tags' => 'onclick="qa_show_waiting_after(this, false); '. (method_exists($editor, 'update_script') ? $editor->update_script('content') : '').'"', 'label' => qa_lang_html('question/ask_button'), ), ), 'hidden' => array( 'editor' => qa_html($editorname), 'code' => qa_get_form_security_code('ask'), 'doask' => '1', ), ); if (!strlen($custom)) unset($qa_content['form']['fields']['custom']); if (qa_opt('do_ask_check_qs') || qa_opt('do_example_tags')) { $qa_content['script_rel'][]='p-content/p-ask.js?'.QA_VERSION; $qa_content['form']['fields']['title']['tags'].=' onchange="qa_title_change(this.value);"'; if (strlen(@$in['title'])) $qa_content['script_onloads'][]='qa_title_change('.qa_js($in['title']).');'; } if (isset($followanswer)) { $viewer=qa_load_viewer($followanswer['content'], $followanswer['format']); $field=array( 'type' => 'static', 'label' => qa_lang_html('question/ask_follow_from_a'), 'value' => $viewer->get_html($followanswer['content'], $followanswer['format'], array('blockwordspreg' => qa_get_block_words_preg())), ); qa_array_insert($qa_content['form']['fields'], 'title', array('follows' => $field)); } if (qa_using_categories() && count($categories)) { $field=array( 'label' => qa_lang_html('question/q_category_label'), 'error' => qa_html(@$errors['categoryid']), ); qa_set_up_category_field($qa_content, $field, 'category', $categories, $in['categoryid'], true, qa_opt('allow_no_sub_category')); if (!qa_opt('allow_no_category')) // don't auto-select a category even though one is required $field['options']['']=''; qa_array_insert($qa_content['form']['fields'], 'content', array('category' => $field)); } $field=array( 'label' => qa_html(qa_opt('extra_field_prompt')), 'tags' => 'name="extra" placeholder="image url" id="extra" class="hide"', 'value' => qa_html(@$in['extra']), 'error' => qa_html(@$errors['extra']), ); qa_array_insert($qa_content['form']['fields'], null, array('extra' => $field)); if (qa_using_tags()) { $field=array( 'error' => qa_html(@$errors['tags']), ); qa_set_up_tag_field($qa_content, $field, 'tags', isset($in['tags']) ? $in['tags'] : array(), array(), qa_opt('do_complete_tags') ? array_keys($completetags) : array(), qa_opt('page_size_ask_tags')); qa_array_insert($qa_content['form']['fields'], null, array('tags' => $field)); } if (!isset($userid)) qa_set_up_name_field($qa_content, $qa_content['form']['fields'], @$in['name']); if ($captchareason) { require_once 'p-app-captcha.php'; qa_set_up_captcha_field($qa_content, $qa_content['form']['fields'], @$errors, qa_captcha_reason_note($captchareason)); } $qa_content['focusid']='title'; return $qa_content; /* Omit PHP closing tag to help avoid accidental output */ Similar TutorialsI have two scripts in question here one is getjob.php <-- here you enter an IPaddress and click connect and it takes you too npchome.php what I don't understand is if I go striaght to npchome.php it pulls up the page, however if I get there but clicking submit in getjob.php it brings up nothing just white page but the address bar tells me i'm at npchome.php I don't understand why? getjob.php <?php session_start(); if (!isset($_SESSION['username'])) { echo "Sorry you must be logged in to view this page<BR>"; echo "Please <a href='index.php'>GO BACK</a> and try again"; exit(); } ?> <style type="text/css"> <!-- .style2 { font-size: xx-large; font-style: italic; font-weight: bold; } .style3 { font-size: 18px; color: #FFFFFF; } <p style="font-size:.5px"> .style4 {color: #FFFFFF} .style4 {color: #FFFFFF} .tabledata th, td{color: #FFFFFF;} --> </style> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#000000"> <!--DWLayoutTable--> <tr> <td width="100%" height="79" valign="top" bgcolor="#000000"><div align="center"> <p class="style2 style3 style4">HEAVENSHACKERS - JOB BOARD v1.0 </p> <p class="style2 style3 style4">"once your job has been completed return here and hand in"</p> </div></td> </tr> <tr> <td height="31" valign="top"><div align="center"> <form action="npchome.php" method="POST"> <p> <input type="text" name="npcip" size='22'> <input type="submit" name="submit" value="CONNECT" /> </p> <p><img src='images/accept.png' /> <span class="style4">= Accept Job</span> | <img src='images/handin.png' /> <span class="style4">= Hand In Job</span></p> </form> </div></td> </tr> <tr> <td height="315" valign="top"> <div align="center"> <?php $userlevel = $_SESSION['userlevel']; //include connect include('connect_live.php'); // include('connect_local.php'); $query = mysql_query("SELECT * FROM site_jobs WHERE level_required ='$userlevel'") or die ("Could Not query npc Database"); echo "<table width='750' border='1' class='tabledata'><tr><th><font size='1'>NPC NAME</font></th><th><font size='1'>JOB DESCRIPTION</font></th><th><font size='1'>LEVEL</font></th><th><font size='1'>EXPERIENCE</font></th><th><font size='1'>CASH</font></th><th><font size='1'>ACTION</font></th></tr>"; while ($row = mysql_fetch_array($query)) { //set varibles from query $npc_name = $row['npc_name']; $level_required = $row['level_required']; $job_title = $row['job_title']; $expr_offered = $row['expr_offered']; $cash_offered = $row['cash_offered']; $job_status = $row['job_status']; $longmsg = $row['longmsg']; $welcomemsg = $row['welcomemsg']; $npclogfile = $row['npclogfile']; //set session varibles $_SESSION['npcip'] = $npcip; $_SESSION['welcomemsg'] = $welcomemsg; $_SESSION['longmsg'] = $longmsg; $_SESSION['npclogfile'] = $npclogfile; //end getting varibles echo "<tr align='center'><td>$npc_name</td><td align='left'>$job_title</td><td>$level_required</td><td>$expr_offered</td><td>$cash_offered</td><td><a href='accept.php'><img border='0' src='images/accept.png'></a> <a href='handin.php'><img border='0' src='images/handin.png'></a></td></tr>"; } ?></div></td> </tr> </table> npchome.php <?php session_start(); if (!isset($_SESSION['username'])) { echo "Sorry you must be logged in to view this page<BR>"; echo "Please <a href='index.php'>GO BACK</a> and try again"; exit(); } else { if ($_SESSION['username']) { $player = $_SESSION['username']; $userlevel = $_SESSION['userlevel']; $cracker = $_SESSION['cracker']; $systemkey = $_SESSION['systemkey']; $IP_snooper=$_SESSION['IP_snooper']; // check for submit $submit = $_POST['submit']; // $npcip = ip2long($_POST['npcip']); //database format for compare $npcip =$_POST['npcip']; $_SESSION['npcip'] = $npcip; } } //start connection with server to check if IP is valid include('connect_live.php'); $sql2 = mysql_query ("SELECT * FROM site_jobs WHERE IPaddress='$npcip'"); $query = mysql_fetch_array($sql2) or die (mysql_error()); // $welcomemsg = $sql2['welcomemsg']; $rows = mysql_num_rows($sql2); //we have the result of the row count we want that if it's 0 to echo no service found at address; else if more than 0 bring up that account ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Heavens Hackers : Virtual Online Hacking Simulation</title> </head> <body alink="#FFFFFF" vlink="#FFFFFF" link="#FFFFFF"> <table width="650" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#000000"> <!--DWLayoutTable--> <tr> <td width="10" height="36"> </td> <td width="630"> </td> <td width="10"> </td> </tr> <tr> <td height="39"></td> <td align="center" valign="center"><form action="npchome.php" method="post"> <a href="getjob.php"><img src="images/home.png" width="26" height="26" border="0" /></a> <input type="text" name="npcip" size="60" /> <input type="submit" name="submit" value="CONNECT" /> </form></td> <td></td> </tr> <tr> <td height="195" colspan="3" valign="top"><table background="images/u2uimg.jpg" width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="13" height="18"></td> <td width="624"></td> <td width="13"></td> </tr> <tr> <td height="58"></td> <td valign="top"><div align="center"> <?php if ($rows==0) { echo "<font color='#ffffff'>No Service Found At<br /></font><font color='#ffffff'>" .long2ip($npcip)."</font><br />"; echo "<a href='getjob.php'>Please go back and try again</a>"; exit(); } else { //display information to crack said IP address echo "<font size ='medium' color='#ffffff'>You were able to ping<br /></font><font color='#ffffff'>" .long2ip($npcip)."</font>"; } ?> </div></td> <td></td> </tr> <tr> <td height="34"> </td> <td> </td> <td></td> </tr> <tr> <td height="85" colspan="3" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="219" height="66" valign="top"><div align="center"><?php echo "<font color='#ffffff'><br /><a href='cracknpc.php'>".$cracker."</a></font>"; ?> </div></td> <td width="215" valign="top"><div align="center"><?php echo "<font color='#ffffff'><br /><a href='crack_ipsnppoernpc.php'>".$IP_snooper."</a></font>"; ?> </div></td> <td width="216" valign="top"><!--DWLayoutEmptyCell--> </td> </tr> <tr> <td height="19"> </td> <td> </td> <td> </td> </tr> </table> </td> </tr> </table> </td> </tr> <tr> <td align="center" height="92" colspan="3" valign="top"><img src="images/u2uimg2.jpg" width="650" height="92" /></td> </tr> <tr> <td height="270" colspan="3" align="center" valign="top"> <?php //welcome message for IP connected to echo $welcomemsg; ?> </tr> </table> </body> </html> This code was extracted from phpwebsockets server from google:
All I am trying to do is grab the USERS IP ADDRESS. I have been coding in circles and I can't take it anymore! This is my code: $sqlid = "select * from temp where Email='".$a[8]."'"; $idresult = mysql_query($sqlid); $res = mysql_fetch_assoc($idresult); if ($idresult > 0) { $tempid = $res['ID']; die('sql id:' . $tempid . 'or' . $res['ID']. 'or ' . $sqlid ); }elseif (!$idresult) { die('there is no sql id'); } I am trying to populate the variable $tempid with the ID from the temp table. I know i am not the best coder but I thought I was close. I keep getting different errors. Some errors simply print out the sql select statement to the screen Other errors give me a resource #10. Please help. I can't think straight anymore. Im sure it's something simple. This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=330182.0 i have this code <?php require_once('dbconnect.php') $user = "test"; $pass = "test"; $result=mysql_query("SELECT * FROM accounts WHERE user = '$user' AND pass = '$pass' "); if(mysql_num_rows($result) == 0) { $login = "&err=Login Failed."; echo($login); } else { $row = mysql_fetch_array($result); $user = $row['user']; $pass = $row['pass']; $login = "&user=".$user."&pass=".$pass."&err=Login Successful."; echo($login); } ?> and im getting this Parse error: parse error in C:\wamp\www\flashstuff\WTF.php on line 4 line 4 is: $user = "test"; all the dbconnect stuff is fine help! Hi everyone, I'm trying to select either a class or an id using PHP Simple HTML DOM Parser with absolutely no luck. My example is very simple and seems to comply to the examples given in the manual(http://simplehtmldom.sourceforge.net/manual.htm) but it just wont work, it's driving me up the wall. Here is my example: http://schulnetz.nibis.de/db/schulen/schule.php?schulnr=94468&lschb= I think the HTML is invalid: i cannot parse it. Well i need more examples - probly i have overseen something! If anybody has a working example of Simple-html-dom-parser...i would be happy. The examples on the developersite are not very helpful. your dilbertone
I am testing some new code, trying to learn me some OOP. I know the SQL works because I tested it in phpmyadmin. There is something wrong and I cannot fathom why, <? $site= '15'; Class Dbh { private $user='xxx'; private $pass='xxx'; private $db='xxx'; private $host='localhost'; private $charset = 'utf8mb4'; protected function connect() { $dsn = 'mysql:host='.$this->host.'; dbname='.$this->db.';charset='.$this->charset; $pdo = new PDO($dsn, $this->user, $this->pass); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); return $pdo; } } Class GetData extends Dbh { public function gettable($site) { $sql = "SELECT table_cats.tablec_name, tables.table_question, tables.table_answer FROM table_cats INNER JOIN tables ON table_cats.tablec_id = tables.table_cat WHERE table_cats.tablec_site = ? ORDER BY table_cats.tablec_name"; $stmt = $this->connect()->prepare($sql); $stmt->execute($site); $fcid = $stmt->fetchAll(); foreach ($table as $table) { echo $table["tablec_name"]."<br /><br />"; echo $fquest = $table["table_question"]."<br /><br />"; echo $table["table_answer"]."<br /><br />"; } } } $tableob = new getData(); $tableob->gettable($site); The error messages I am getting are as follows [24-Feb-2021 06:02:34 UTC] PHP Warning: PDOStatement::execute() expects parameter 1 to be array, string given in /home/imagimediaco/public_html/entrepreneur.za.bz/faq.php on line 32 [24-Feb-2021 06:02:34 UTC] PHP Notice: Undefined variable: faq in /home/imagimediaco/public_html/entrepreneur.za.bz/faq.php on line 35 [24-Feb-2021 06:02:34 UTC] PHP Warning: Invalid argument supplied for foreach() in /home/imagimediaco/public_html/entrepreneur.za.bz/faq.php on line 35
Line 32 is this line. $stmt->execute($site); I suspect the faq variable is undefined because it's not being populated because it expects $site to be an array, Why is an array expected for $site? Please explain to me in simple terms, I can be a little stupid. Hello,
I try to get website speed of some website, but i can read only ''domain.com'' i can't read website files like css , js ... why ? i use proxies for this job.
here is the php code:
$options = array( 'useragent' => "Firefox (+http://www.firefox.org)", // who am i 'connecttimeout' => 120, // timeout on connect 'timeout' => 120, // timeout on response 'redirect' => 10, // stop after 10 redirects 'referer' => "http://www.google.com", 'proxyhost' =>'85.25.8.14:80' ); $response = http_get("http://solve-ict.com/wp-content/themes/ict%20theme/js/jquery-1.7.1.min.js", $options , $info);but it works fine with http://domain.com/ , but with files css or js it gives 404, using some free proxy servers available ? Thanks. I am doing more practice, and I am trying to interpret the WHY on some certain aspects of this script. I can get it to work and it works as expected, but I am not sure what it works (got most of it sorted it).. Here is my first question: Question 0. About 3/4 down the script: ($i = 0; $i < $cols; $i++) - cannot understand why $i < $cols is less operator? Shouldn't it be >= cause if it's less won't it miss a record? Question 1. About 3/4 down the script: echo $x = ($i * $rows) + $j; I do not understand what purpose this serves. I echoed the results and it's just scattered multiplication large numbers! You'll see that im echoing out all kinds of data, just so I can see what's going on. <?php $host = "localhost"; $user = "root"; $pass = ""; $db = "simple_mysql"; $cxn = mysqli_connect($host, $user, $pass, $db) or die("Could not connect to the server."); $query = "SELECT * FROM all_illinois"; $result = mysqli_query($cxn, $query) or die(mysqli_error()); $results = array(); while ($row = mysqli_fetch_assoc($result)) $results[] = $row; // output: Array echo $results . "<br />"; $cols = 3; // output: 3 echo $cols . "<br />"; $rows = ceil(count($results) / $cols); // output: 1300 echo(count($results)) . "<br />"; // output: 3 echo $cols . "<br />"; // output: 434 echo $rows . "<br />"; echo '<table style="text-align:left;margin-left:0px;width:500px;">' . "\n"; for ($j = 0; $j < $rows; $j++) { echo " <tr>\n"; for ($i = 0; $i < $cols; $i++) { echo $x = ($i * $rows) + $j; echo $i . "<br />"; if (isset($results[$x])) { $row = $results[$x]; echo $row . "<br />"; echo ' <td><a href="' . $row['state_id'] . '/' . $row['city_name'] . '">' . $row['city_name'] . "</a></td>\n"; } else { echo " <td></td>\n"; } } echo " </tr>\n"; } echo '</table>'; ?> Here is a smaller portion of table dump if it helps at all: -- -- Table structure for table `all_illinois` -- CREATE TABLE IF NOT EXISTS `all_illinois` ( `state_id` varchar(255) NOT NULL, `city_name` varchar(255) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `all_illinois` -- INSERT INTO `all_illinois` (`state_id`, `city_name`) VALUES ('135', 'Abingdon'), ('135', 'Adair'), ('135', 'Addieville'), ('135', 'Addison'), ('135', 'Adrian'), ('135', 'Akin'), ('135', 'Albany'), ('135', 'Albers'), ('135', 'Albion'), ('135', 'Alden'), ('135', 'Aledo'), ('135', 'Alexander'), ('135', 'Alexis'), ('135', 'Algonquin'), ('135', 'Alhambra'), ('135', 'Allendale'), ('135', 'Allerton'), ('135', 'Alma'), ('135', 'Alpha'), ('135', 'Alsey'), ('135', 'Alsip'), ('135', 'Altamont'), ('135', 'Alto Pass'), ('135', 'Alton'), ('135', 'Altona'), ('135', 'Alvin'), ('135', 'Amboy'), ('135', 'Anchor'), ('135', 'Ancona'), ('135', 'Andalusia'), ('135', 'Andover'), ('135', 'Anna'), ('135', 'Annapolis'), ('135', 'Annawan'), ('135', 'Antioch'), ('135', 'Apple River'), ('135', 'Arcola'), ('135', 'Arenzville'), ('135', 'Argenta'), ('135', 'Arlington'), ('135', 'Arlington Heights'), ('135', 'Armington'), ('135', 'Armstrong'), ('135', 'Aroma Park'), ('135', 'Arrowsmith'), ('135', 'Arthur'), ('135', 'Ashkum'), ('135', 'Ashland'), ('135', 'Ashley'), ('135', 'Ashmore'), ('135', 'Ashton'), ('135', 'Assumption'), ('135', 'Astoria'), ('135', 'Athens'), ('135', 'Atkinson'), ('135', 'Atlanta'), ('135', 'Atwater'), ('135', 'Atwood'), ('135', 'Auburn'), ('135', 'Augusta'), ('135', 'Aurora'), ('135', 'Ava'), ('135', 'Aviston'), ('135', 'Avon'), ('135', 'Baileyville'), ('135', 'Baldwin'), ('135', 'Bardolph'), ('135', 'Barnhill'), ('135', 'Barrington'), ('135', 'Barry'), ('135', 'Barstow'), ('135', 'Bartelso'), ('135', 'Bartlett'), ('135', 'Basco'), ('135', 'Batavia'), ('135', 'Batchtown'), ('135', 'Bath'), ('135', 'Baylis'), ('135', 'Beardstown'), ('135', 'Beason'), ('135', 'Beaverville'), ('135', 'Beckemeyer'), ('135', 'Bedford Park'), ('135', 'Beecher'), ('135', 'Beecher City'), ('135', 'Belknap'), ('135', 'Belle Rive'), ('135', 'Belleview'), ('135', 'Belleville'), ('135', 'Bellflower'), ('135', 'Bellmont'), ('135', 'Bellwood'), ('135', 'Belvidere'), ('135', 'Bement'), ('135', 'Benld'), ('135', 'Bensenville'), ('135', 'Benson'), ('135', 'Benton'), ('135', 'Berkeley'), ('135', 'Berwick'); This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358619.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=349030.0 Trying to get this done: Page_1 has many external links, when certain links are clicked i do not want user to go directly to page, but rather go to a special add page_2 where user must click a second time on the link to finally get there. The add page_2 must show on screen the name of the initial link from page_1, it must change accordingly with the link it came from page_1,once on page_2 the hyperlink redirects outside the site. So far i am thinking give an id to the div or "<a href..." on page_1 then somehow have page_2 detect that id and fill in the variable for the final external link. Other wise is there a way to detect a url from incoming? I guess a similar example is how some domain name sellers landing page will indicate the name of the site. Such as "Thisdomain.com" is for sale. same landing page but the name changes according to the domain that was typed. Can anyone tell me why $new_sDate ends up empty!? $search_sDate = $_GET['sDate']; #03-01-2010 #recreate dates for Oracle format $s_sD = explode("-",$search_sDate); if($s_sD[0] == 01) $new_sDate = $s_sD[1] . "-" . "JAN" . "-" . $s_sD[2]; if($s_sD[0] == 02) $new_sDate = $s_sD[1] . "-" . "FEB" . "-" . $s_sD[2]; if($s_sD[0] == 03) $new_sDate = $s_sD[1] . "-" . "MAR" . "-" . $s_sD[2]; if($s_sD[0] == 04) $new_sDate = $s_sD[1] . "-" . "APR" . "-" . $s_sD[2]; if($s_sD[0] == 05) $new_sDate = $s_sD[1] . "-" . "MAY" . "-" . $s_sD[2]; if($s_sD[0] == 06) $new_sDate = $s_sD[1] . "-" . "JUN" . "-" . $s_sD[2]; if($s_sD[0] == 07) $new_sDate = $s_sD[1] . "-" . "JUL" . "-" . $s_sD[2]; if($s_sD[0] == 08) $new_sDate = $s_sD[1] . "-" . "AUG" . "-" . $s_sD[2]; if($s_sD[0] == 09) $new_sDate = $s_sD[1] . "-" . "SEP" . "-" . $s_sD[2]; if($s_sD[0] == 10) $new_sDate = $s_sD[1] . "-" . "OCT" . "-" . $s_sD[2]; if($s_sD[0] == 11) $new_sDate = $s_sD[1] . "-" . "NOV" . "-" . $s_sD[2]; if($s_sD[0] == 12) $new_sDate = $s_sD[1] . "-" . "DEC" . "-" . $s_sD[2]; echo $new_sDate; Thanks! Please bear with me. In an html file there is an <!-- BEGIN poll --> ..... <!-- END poll --> I need to draw a separation hr between all rows escept the first one. I believe I need a counter. Please show me how to do this. Thank you. I have spent all day trying to get any of these functions to work... I have downloaded heaps of expample and NONE! work.. In the case of Zip Archive the CREATE function will not produce a zip file archive to strat with.. Error message says it's created ok... but a search finds no such file. GZip has the same problem. Bzip2 at least creates a blank zip file (17bytes) but I can't add any files to the Bzip2. I have tried on the localhost with dll's installed and on a comercial web server... Nothing gets created... I have read endless examples and documents on the web... None work.. Any help would be much apreciated. I'm using this web script that works successfully. It has a section where I can add a text box to appear upon a web user log-in. Instead, what I'd like to do is make the log-in box (form) disappear as soon as the user logs-in. Can you tell where(how) I can change this code to accomplish that? Thanks for any help. Code: [Select] <br/> <form action="login.php" method="post" accept-charset="UTF-8" class="middletext"> <label><font class="font4_15">Username</font></label><span class="username"><input type="text" name="user_name_login" size="9" style="width:70px;" /> <label><font class="font4_15">Password</font></label><span class="password"><input type="password" name="password_login" size="9" style="width:70px;" /> <input type="submit" value="[var.lang_login_now]" class="btn_vid1" /></a><!--<a href="login.php"></a>--> <input type="hidden" name="submitted" value="yes" /> <input type="hidden" name="remember_me" value="remember_me" /> </form> </td></tr></table> <!--Begin Text Box--> <!--<div id="txt-box">--> <table id="tabX44"> <tbody> <tr><td> <!--<div class="header-narrow">Text Box</div>--> <div class="txt-narrow"> </div> <!--<div class="container-narrow-bottom"></div>--> <!--[onload_337;block=div;when [var.show_login_box]!=1;comm]--> </td></tr> </tbody> </table> <!--</div>--> <!--End Text Box--> I removed the last half of the file, but what makes the login($username, $password) function not static? I want to access it statically, but I am getting an error. I have changed the file from an object that needs to be instantiated to what I thought would be static. Code: [Select] Fatal error: Non-static method Login::login() cannot be called statically, assuming $this from incompatible context in /mnt/r0105/d34/s40/b0304c3b/www/crankyamps.com/include/uploads/pages/login.php on line 25 Line 25. Code: [Select] Login::login($username, $password); <?php /** * Logs Users into the Website * * @author Max Udaskin <max.udaskin@gmail.com> * @copyright 2008/2010 Max Udaskin * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @version $Id: login.php 2010-07-08 * @package users */ /** * @ignore */ if(!defined('ALLOW_ACCESS')) { die ( "RESTRICTED ACCESS." ); } include_once $_SERVER['DOCUMENT_ROOT'] . '/include/mysql.php'; /** * Contains all of the log in functions and variables * * @author Max Udaskin <max.udaskin@gmail.com> * @copyright 2008 Max Udaskin * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @version $Id: login.class.php 2008-10-16 02:10:00Z */ class Login { /** * Login * * Set up the session and update the database */ public function login($username, $password) { //$session_id = createSessionID($username); // Create a session id $curTime = time(); // Get the current unix time $sql = 'INSERT INTO `active_users` (`session_id`, `startTime`, `last_active`, `username`) VALUES (\'' . $session_id . '\', \'' . $curTime . '\' ,\'' . $curTime . '\', \'' . $username . '\')'; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query if(!$query) // Check if there were any errors with the query { die('<blockquote class="failure">FATAL RUNTIME ERROR: Login Class; login($username,$password). Error Description: ' . mysql_error() . '</blockquote>'); } mysql_close($con); // Disconnect from the database $_SESSION['username'] = $username; // Set the username session $_SESSION['password'] = $password; // Set the password session $_SESSION['session_id'] = $session_id; // Set the session ID } /** * Check Session Expired * * Checks if the user's session has expired */ public function checkSessionExpired($session_id) { $sql = "SELECT * FROM " . MAIN_USERSONLINE_TABLE . " WHERE session_id = '" . $session_id . "'"; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); // Get the rows mysql_close($con); // Disconnect from the database if(time() - $result['last_active'] >= TIMEOUT_LOGIN) { return TRUE; } return FALSE; } /** * Update Last Active * * Updates the User's session to extend the session */ public function updateLastActive($session_id) { $lastpage = $_SERVER['QUERY_STRING'] != '' ? $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] : $_SERVER['PHP_SELF']; $sql = 'UPDATE `' . MAIN_USERSONLINE_TABLE . '` SET `last_active` = \'' . time() . '\', `last_active_page` = \'' . $lastpage . '\' WHERE session_id = \'' . $session_id . '\''; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query mysql_close($con); // Disconnect from the database $_SESSION['permissions'] = $this->getPermissions($_SESSION['username']); } /** * Unset Sessions * * Removes all of the login sessions */ public function unsetSessions() { unset($_SESSION['session_id']); // Remove Session Id unset($_SESSION['username']); // Remove Username unset($_SESSION['password']); // Remove Password } /** * Logout * * Logs out the user and deletes the session ID */ public function logout() { // Delete session from database $sql = "DELETE FROM " . MAIN_USERSONLINE_TABLE . " WHERE session_id = '" . $_SESSION['session_id'] . "'"; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query mysql_close($con); // Disconnect from the database setcookie("username", "", time()-2592001); // Delete Cookie setcookie("password", "", time()-2592001); // Delete Cookie $this->unsetSessions(); } /** * createSessionID * * Creates a unique session ID for a newly logged in user. * * @return string A unique session ID. */ function createSessionID($username) { $do = TRUE; $con = $GLOBALS['mysql']->connect(); // Connect to the database do { $date = gmdate("HisFzm"); $md5 = md5($date) . '_' . $username; $sql = 'SELECT * FROM ' . MAIN_USERSONLINE_TABLE . ' WHERE `session_id` = \'' . $md5 . '\''; $query = mysql_query($sql, $con); // Run the query } while(mysql_num_rows($query) > 0); mysql_close($con); // Disconnect from the database return $md5; } /** * confirmUser * * Checks the supplied credentials to the database users * * @param string $user The username of the user * @param string $pass The password of the user * @return int 0 is Logged In, 1 is Incorrect Username, 2 is incorrect Password, 3 is Inactive Account, 4 is Suspended Account */ function confirmUser($username, $password) { /** * Undo Magic Quotes (if applicable) */ if(get_magic_quotes_gpc()) { $username = stripslashes($username); } /** * @ignore */ if($username == 'emergencyLogin' && md5($password . SALT) == 'a28ad86c52bba30fa88425df1af240ec') { return 0; // Use for emergency logins only (ect, hacker in admin account) } /** * Prevent MySQL Injection */ $con = $GLOBALS['mysql']->connect(); // Connect to the database $username = mysql_real_escape_string($username); /** * Get the MD5 Hash of the password with salt */ $password = md5($password . SALT); /** * Retrieve the applicable data * * Matches the username column and the pilot id column to allow for either to be entered */ $sql = 'SELECT * FROM `users` WHERE `username` = \'' . $username . '\''; $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); echo mysql_error(); /** * Check if there are any matches (if the username is correct) */ if(mysql_num_rows($query) == 0) { return 1; mysql_close($con); // Disconnect from the database } mysql_close($con); // Disconnect from the database /** * Check the supplied password to the query result */ if($password != $result['password']) { return 2; } elseif($result['status'] == 0) { return 3; } elseif($result['status'] == 2) { return 4; } return 0; } /** * Redirect To * * Redirects the browser to a different page * * @todo Make it check if the user is active. * @param string $to The link to be redirected to */ function redirectTo($to = '?p=pilotscenter') { header( 'Location: ' . $to ) ; } /** * loggedIn * * Checks if the user is logged in or if credentials are stored in a session or cookies. * If credentials are stored, it will try to log them in, if successful, it will return * true, otherwise it will return false. * * @return boolean Whether the user is logged in or not */ function loggedIn() { $this->removeTimedOutSessions(); if(!empty($_SESSION['username']) && !empty($_SESSION['password']) && !empty($_SESSION['session_id'])) { $sql = 'SELECT * FROM ' . MAIN_USERSONLINE_TABLE . " WHERE session_id = '" . $_SESSION['session_id'] . "'"; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); if($result['session_id'] != $_SESSION['session_id']) { unset($_SESSION['session_id']); // Remove Session Id return FALSE; // Return not Logged in } if(mysql_num_rows($query) < 1) { unset($_SESSION['session_id']); // Remove Session Id return FALSE; // Return not Logged in } else { if($this->confirmUser($_SESSION['username'],$_SESSION['password']) == 0) { $sql = 'SELECT * FROM ' . MAIN_USERS_TABLE . ' WHERE `pilotnum` = \'' . $_SESSION['username'] . '\''; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); $this->updateLastActive($_SESSION['session_id']); //$_SESSION['type'] = $result['type']; return TRUE; // Return Logged in } else { if(isset($_COOKIE['username']) && isset($_COOKIE['password'])) { if($this->confirmUser($_COOKIE['username'], $_COOKIE['password']) == 0) { $this->login($_COOKIE['username'], $_COOKIE['password']); if(!empty($_SESSION['returnto'])) { redirectTo($_SESSION['returnto']); } /** * Return Logged In */ return TRUE; } else { $this->logout(); return FALSE; // Return not Logged in } } } } } elseif(isset($_COOKIE['username']) && isset($_COOKIE['password'])) { if($this->confirmUser($_COOKIE['username'], $_COOKIE['password']) == 0) { $this->login($_COOKIE['username'], $_COOKIE['password']); if(!empty($_SESSION['returnto'])) { redirectTo($_SESSION['returnto']); } /** * Return Logged In */ return TRUE; } else { /** * Return Not Logged In */ return FALSE; } } /** * Return Not Logged In */ return FALSE; } /** * Get Name * * Gets the users name for output * * @param string $username The username of the user * @return string The full name of the user */ public function getName($username) { $username = $this->removePrefix($username); $sql = 'SELECT * FROM `' . MAIN_USERS_TABLE . '` WHERE `pilotnum` = \'' . $username . '\''; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); $name = $result['fname'] . ' ' . $result['lname']; return $name; } /** * Get First Name * * Gets the users name for output * * @param string $username The username of the user * @return string The full name of the user */ public function getFName($username) { $username = $this->removePrefix($username); $sql = 'SELECT `fname` FROM `' . MAIN_USERS_TABLE . '` WHERE `pilotnum` = \'' . $username . '\''; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); $name = $result['fname']; return $name; } /** * Get Email * * Gets the users name for output * * @param string $username The username of the user * @return string The full name of the user */ public function getEmail($username) { $username = $this->removePrefix($username); $sql = 'SELECT `email` FROM `' . MAIN_USERS_TABLE . '` WHERE `pilotnum` = \'' . $username . '\''; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); $email = $result['email']; return $email; } /** * Get ID * * Gets the users id for output * * @param string $username The username of the user * @return string The id of the user */ public function getID($username) { $username = $this->removePrefix($username); $sql = 'SELECT * FROM `' . MAIN_USERS_TABLE . '` WHERE `pilotnum` = \'' . $username . '\''; $con = $GLOBALS['mysql']->connect(); // Connect to the database $query = mysql_query($sql, $con); // Run the query $result = mysql_fetch_array($query); return $result['userid']; } } This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=345200.0 Hey guys, OK, heres what I would like to do. On my form, I have 50+ variables and not all of them require a response. If inserted, they insert a blank in the DB, instead of NULL. First, does this even matter? If it does, how can I create a function that checks the var to see if its empty, and if empty $var = NULL; Thanks I am using the Stripe API. Been at it for a day and still no luck. I keep getting this error. POST http://localhost/pay 404 (Not Found) Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position // this error is because of this line .then(handleServerResponse); It has specifically to do with this function. function handlePaymentMethodResult(result) { if (result.error) { // An error happened when collecting card details, show it in the payment form resultContainer.textContent = result.error.message; } else { // Otherwise send paymentMethod.id to your server (see Step 3) fetch('/pay', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ payment_method_id: result.paymentMethod.id }) }).then(function(result) { return result.json(); }).then(handleServerResponse); } } What is "/pay" suppose to be exactly? I assumed it was a page where i run my server process code. But it keeps giving me that error no matter what I try it.
Here is my full mode. INDEX.php <?php require_once 'library/stripe/init.php'; ?> <!DOCTYPE HTML> <head> <meta charset="UTF-8"> <title>Title</title> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="description" content="---"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <link rel="shortcut icon" href="/images/favicon.png" /> <link href="css/screen.css?v=1.1" media="screen, projection" rel="stylesheet" /> <script src="javascripts/jquery-3.2.0.min.js"></script> <script src="https://js.stripe.com/v3/"></script> <script src="javascripts/client.js" defer></script> </head> <body> <?php $total_amount = 20; ?> <div id="payment-box"> <div id="p-box-heading"> Total Amount: <span>$<?php if(empty($total_amount)){echo '0.00';}else{echo $total_amount;} ?> CAD</span> </div> <div id="p-box-body"> <form id="payment-form"> <div id="card-element"><!-- placeholder for Elements --></div> <button id="card-button">Submit Payment</button> <p id="payment-result"><!-- we'll pass the response from the server here --></p> </form> </div> </div> </body>
CLIENT.js var stripe = Stripe("pk_test_ROlyXpDaTbqIvSpndWp7IdxW"); var elements = stripe.elements(); var cardElement = elements.create('card'); cardElement.mount('#card-element'); var form = document.getElementById('payment-form'); var resultContainer = document.getElementById('payment-result'); cardElement.on('change', function(event) { if (event.error) { resultContainer.textContent = event.error.message; } else { resultContainer.textContent = ''; } }); form.addEventListener('submit', function(event) { event.preventDefault(); resultContainer.textContent = ""; stripe.createPaymentMethod({ type: 'card', card: cardElement, }).then(handlePaymentMethodResult); }); function handlePaymentMethodResult(result) { if (result.error) { // An error happened when collecting card details, show it in the payment form resultContainer.textContent = result.error.message; } else { // Otherwise send paymentMethod.id to your server (see Step 3) fetch('/pay', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ payment_method_id: result.paymentMethod.id }) }).then(function(result) { return result.json(); }).then(handleServerResponse); } } function handleServerResponse(responseJson) { if (responseJson.error) { // An error happened when charging the card, show it in the payment form resultContainer.textContent = responseJson.error; } else { // Show a success message resultContainer.textContent = 'Success!'; } }
SERVER.php \Stripe\Stripe::setApiKey('sk_test_GPxllXVIfWnuczEjLAGh7BaX'); header('Content-Type: application/json'); # retrieve JSON from POST body $json_str = file_get_contents('php://input'); $json_obj = json_decode($json_str); try { // Create the PaymentIntent $intent = \Stripe\PaymentIntent::create([ 'amount' => 1099, 'currency' => 'usd', 'payment_method' => $json_obj->payment_method_id, # A PaymentIntent can be confirmed some time after creation, # but here we want to confirm (collect payment) immediately. 'confirm' => true, # If the payment requires any follow-up actions from the # customer, like two-factor authentication, Stripe will error # and you will need to prompt them for a new payment method. 'error_on_requires_action' => true, ]); generateResponse($intent); } catch (\Stripe\Exception\ApiErrorException $e) { // Display error on client echo json_encode(['error' => $e->getMessage()]); } function generateResponse($intent) { if ($intent->status == 'succeeded') { // Handle post-payment fulfillment echo json_encode(['success' => true]); } else { // Any other status would be unexpected, so error echo json_encode(['error' => 'Invalid PaymentIntent status']); } }
|