I am learning how to make a form and I dont know how to remove these marks. I attach picture and also code:
https://gist.github.com/pawelwch/4fed1a17ecd472fe8f7f0c2faf685f5f
I am learning how to make a form and I dont know how to remove these marks. I attach picture and also code:
https://gist.github.com/pawelwch/4fed1a17ecd472fe8f7f0c2faf685f5f
Hi
How can I custom sort this array into any order I specify by say the object key - name like this
P2,P1,P3
or by id
sku991,sku838,sku123,
Here is a PHP var dump
array(3) { [0]=> object(stdClass)#212 (2) { ["id"]=> string(36) "sku838" ["name"]=> string(61) "P1" } [1]=> object(stdClass)#235 (2) { ["id"]=> string(36) "sku991" ["name"]=> string(61) "P2" } [2]=> object(stdClass)#240(2) { ["id"]=> string(36) "sku123" ["name"]=> string(61) "P3" } }
Thankyou
Hi guys, hoping someone can help, i have a small piece of code to query a database table, basically for a login script, however for some reason its just not working.. i have been through this small piece of code numerous times and i just cannot see the problem.. does anyone have any insights..
Hi everyone I am having a hard time on how to subtract the two arrays with the same value.
I have two arrays which hold the data of my products. Sample below.
$transfer_in array
Array ( [0] => Array ( [product_id] => 2 [product_qty] => 32 [product_pcs] => 0 ) [1] => Array ( [product_id] => 3 [product_qty] => 353 [product_pcs] => 2 ) [2] => Array ( [product_id] => 5 [product_qty] => 11 [product_pcs] => 1 ) )
$transfer_out array
Array ( [0] => Array ( [product_id] => 5 [product_qty] => 1 [product_pcs] => 1 ) )
Now I have to subtract the two arrays with specific product_id the product. If product_id from both arrays are the same/ exist then subtract it. $transfer_in['product_qty']-$transfer_out['product_qty'] and $transfer_in['product_pcs']-$transfer_out['product_pcs']
How can I subtract each product_qty and product_pcs with same product_id on both arrays and put them as one array?
This is the expected ouput:
$output = Array ( [0] => Array ( [product_id] => 2 [product_qty] => 32 [product_pcs] => 0 ) [1] => Array ( [product_id] => 3 [product_qty] => 353 [product_pcs] => 2 ) [2] => Array ( [product_id] => 5 [product_qty] => 10 [product_pcs] => 0 ) )
I tried below links but cant complete, if any one of these works or any other idea, pls share it, Thanks in advance...
https://developers.google.com/drive/v3/web/folder
http://www.7logic.info/2016/11/create-f ... g-php.html
https://developers.google.com/drive/v3/ ... kstart/php
Can anyone please help me? normally i can fix this error but for some reason it just doesnt make since in this case to me.
The error im getting is:
Parse error: syntax error, unexpected ''$2y$10$fFYyZWTdAcewqFByXX5Wvu' (T_CONSTANT_ENCAPSED_STRING) in
/home/xxxx/xxxxxxxx.com/pass_test.php on line 2
here is the code:
<?php $hash = '$2y$10$fFYyZWTdAcewqFByXX5Wvu/UuAk8dwYYjOV27SN/9RPea6TeU9Q0u'; if (password_verify('rasmuslerdorf', $hash)) { echo 'Password is valid!'; } else { echo 'Invalid password.'; } echo "<br>"; $options10 = [ 'cost' => 10,]; $hash = password_hash('test',PASSWORD_BCRYPT,$options10); echo "10: ".$hash; echo "<br>"; ?>
I want to create a countdown using php, and retrieve data from the mysql database. Is it possible ? live countdown displays seconds of time continuously, and continues to decrease.
I've make it, but the seconds are not running. so it should be refreshed to be reduced.
I hope there is someone who can help me on this issue.
Big Thanks For Me,
Hi,
I have to develop a php client which connects to a soap webservice server.
With SoapUI, I can test the webservice which is working fine.
But from my php client, I get the following error:
syntax error near <<from>>
Here is my php client code:
<?php
$wsdl='http://intrageo.cannes.fr:81/AdressseRecherche/searchByWhereClause?wsdl';
$trace=true;
$exceptions=false;
$xml_array['context']='?';
$xml_array['table']='adr_digadr';
$xml_array['colonneARecuperer']='numero';
$xml_array['clauseWere']='nomvoie=\'BOULEVARD COINTET\'';
$xml_array['nbMaxLignes']=10;
try{
$client= new SoapClient($wsdl,array('trace' =>$trace,'exceptions' =>$exceptions));
$response=$client->getDistinctValue($xml_array);
}
catch (Exception $e)
{
echo "error!";
echo $e->getMesssage();
echo 'Last response: '.$client->_getLastResponse();
}
var_dump($response);
?>
Thanks a lot for help.
Hey guys,
I needed to covert the $main array in to a string so I used json_encode to do it but now I’m unsure how to get just the key values for $main[0] and $main[1] – can anyone help?
main array:
Array ( [0] => Array ( [25256] => 1 ) [1] => Array ( [50005] => 1 ) [2] => Array ( [301] => 1 [2318] => 1 [13403] => 1 [49489] => 1 ) )
current code and output:
$com_id = json_encode($main[0]); = {"25256":1} $dom_id = json_encode($main[1]); = {"50005":1} $car_id = json_encode($main[2]); = {"301":1,"2318":1,"13403":1,"49489":1}
Desired output:
$com_id = {"25256"} $dom_id = {"50005"} $car_id = {"301":1,"2318":1,"13403":1,"49489":1}
Hi guys,
So I'm fairly new to PHP and someone made a script for me a while ago and made me pay up front etc and I'm in the dumps and have a major issue or simple issue, I don't know, I don't want to hire ANOTHER freelancer to drop me in the dumps again and not respond to my emails or anything like that, again.
So the issue I'm having here is; I'm receiving this error;
"Warning: Declaration of thread::canView($id, $username, $powerLevel) should be compatible with forum::canView($id, $rank) in /*************/structure/forum.thread.php on line 0"
In every Forum catagory I made on my test site.
This is the full corresponding code in question:
<?php /* * @FORUM:THREAD * ~~~~~~~~~~~~ * @FILE DESCRIPTION: For threads * @LAST MODIFIED: June 5, 2012 */ class thread extends forum { public function retrieveThreads($start, $per_page, $f) { return $this->database->processQuery("SELECT `id`,`title`,`username`,`lastpost`,`date`,`lastposter`,`sticky`,`lock`,`hidden`,`moved` FROM `threads` WHERE `parent` = ? ORDER BY `sticky` DESC, `lastpost` DESC LIMIT $start,$per_page", array($f), true); } /* * @METHOD checkExistence * @DESC check if the thread exists */ public function checkExistence($id) { $this->database->processQuery("SELECT * FROM `threads` WHERE `id` = ? LIMIT 1", array($id), false); return ($this->database->getRowCount() == 1) ? $x = true : $x = false; } /* * @METHOD canView * @DESC checks if the user has permissions to see thread */ public function canView($id, $username, $powerLevel) { //extract thread details $thread = $this->database->processQuery("SELECT `parent`,`hidden` FROM `threads` WHERE `id` = ? LIMIT 1", array($id), true); $canSee = true; //get the parent's type $parent = $this->database->processQuery("SELECT `type` FROM `forums` WHERE `id` = ? LIMIT 1", array($thread[0]['parent']), true); if($parent[0]['type'] > 2) { //if it's a protected forum, make sure they are the thread owner or staff in order to view if($parent[0]['type'] == 3 && ($username != $thread[0]['username'] && $powerLevel < 3)) $canSee = false; //forum moderator forum, let only moderators view it if($parent[0]['type'] == 4 && $powerLevel < 3) $canSee = false; //administrator forum, let only administrators see it if($parent[0]['type'] == 5 && $powerLevel < 4) $canSee = false; //member forum, let only members see it if($parent[0]['type'] == 6 && !isset($_COOKIE['user'])) $canSee = false; } //only let staff view hidden threads if($thread[0]['hidden'] == 1 && $powerLevel < 3) $canSee = false; return $canSee; } /* * @METHOD coverThread * @DESC hides the thread (users can still visit, though) */ public function coverThread($id, $rank) { //extract current status of post $status = $this->database->processQuery("SELECT `status` FROM `threads` WHERE `id` = ? LIMIT 1", array($id), true); if($rank > 2) $this->database->processQuery("UPDATE `threads` SET `status` = ? WHERE `id` = ? LIMIT 1", array(($status[0]['status'] == 0) ? 1 : 0, $id), false); } /* * @METHOD Thread * @DESC hides the thread */ public function hideThread($id, $rank) { //extract current status of post $status = $this->database->processQuery("SELECT `hidden` FROM `threads` WHERE `id` = ? LIMIT 1", array($id), true); if($rank > 2) $this->database->processQuery("UPDATE `threads` SET `hidden` = ? WHERE `id` = ? LIMIT 1", array(($status[0]['hidden'] == 0) ? 1 : 0, $id), false); } /* * @METHOD lock * @DESC locks a thread */ public function lock($id, $rank = 0) { //make sure it exists $thread = $this->database->processQuery("SELECT `lock` FROM `threads` WHERE `id` = ? LIMIT 1", array($id), true); //take action if they are staff if($this->database->getRowCount() == 1 && $rank > 2) $this->database->processQuery("UPDATE `threads` SET `lock` = ? WHERE `id` = ? LIMIT 1", array(($thread[0]['lock'] == 1) ? $do = 0 : $do = 1,$id), false); } /* * @METHOD escalate * @DESC function for mods to get an admin to quickly see thread * @DESC only escalate if not already escalated */ public function escalate($id, $rank, $reason) { if(!$this->isEscalated($id) && $rank > 2) $this->database->processQuery("UPDATE `threads` SET `escalated` = 1, `reason` = ? WHERE `id` = ? LIMIT 1", array($reason, $id), false); } /* * @METHOD isEscalated * @DESC checks if the thread is escalated */ public function isEscalated($id) { $thread = $this->database->processQuery("SELECT `escalated` FROM `threads` WHERE `id` = ? LIMIT 1", array($id), true); return ($thread[0]['escalated'] == 1) ? true : false; } /* * @METHOD canReply * @DESC checks if the user is allowed to reply */ public function canReply($id, $powerLevel) { //extract thread details $thread = $this->database->processQuery("SELECT `lock`,`moved` FROM `threads` WHERE `id` = ? LIMIT 1", array($id), true); //return if they can reply or not return (($thread[0]['lock'] == 1 && $powerLevel < 3) || !empty($thread[0]['moved']) || !isset($_COOKIE['user'])) ? $canReply = false : $canReply = true; } /* * @METHOD preTitle * @DESC get the lock/sticky icon before the thread's title * @PARAM $rank rank of the user viewing * @PARAM $location where the user is at (viewforum.php/viewthread.php) */ public function preTitle($id, $rank, $location = 1) { $data = $this->database->processQuery("SELECT `lock`,`sticky` FROM `threads` WHERE `id` = ?", array($id), true); $extra = ''; if($rank > 2 && $location == 0) $extra .= '<input type="checkbox" name="selection[]" value="'. $id .'"> <img src="../img/forum/modify.png" id="thread-'. $id .'"> '; if($data[0]['sticky'] == 1) $extra .= '<i class="fa fa-sticky-note"></i> '; if($data[0]['lock'] == 1) $extra .= '<i class="fa fa-lock"></i> '; return $extra; } /* *@METHOD hasReplies *@DESC returns number of replies */ public function getReplies($id) { $this->database->processQuery("SELECT * FROM `posts` WHERE `thread` = ?", array($id), false); return $this->database->getRowCount(); } /* * @METHOD getPostType * @DESC gets the type of the post to display (like hidden, fmod, etc) * @PARAM $id : id of the thread * @PARAM $status : status (hidden/public) of the thread * @PARAM $rank : the rank of the user that posted it */ public function getPostType($status, $creator, $hide = false, $highlight = false) { $data = $this->database->processQuery("SELECT `acc_status`,`donator` FROM `users` WHERE `username` = ? LIMIT 1", array($creator), true); $rank = $data[0]['acc_status']; if($status == 1) { $type = 'message hid'; } elseif($hide) { $type = 'message moved'; } elseif($data[0]['donator'] == 1 && $rank < 2) { $type = 'message donator'; } else { $included = ($highlight) ? 'msghighlight' : null; switch($rank) { case 3: $type = 'message mod '. $included; break; case 4: $type = 'message jmod '. $included; break; default: //$type = 'message '. (($_COOKIE['halloween_theme'] == 'true') ? 'halloween' : '') . $included; HALLOWEEN $type = 'message '. $included; break; } } return $type; } /* * @METHOD getPageNum * @DESC gets the page of the specifided post * @PARAM $post the id of the post (NOT THREAD) we'll be going to * @PARAM $thread the id of the thread * @PARAM $per_page derp */ public function getPageNum($post, $thread, $per_page = 10) { //make sure the selected post exists $this->database->processQuery("SELECT * FROM `posts` WHERE `thread` = ? AND `id` = ? LIMIT 1", array($thread, $post), false); if($this->database->getRowCount() == 1) { //get number of results $thread = $this->database->processQuery("SELECT * FROM `posts` WHERE `thread` = ? ORDER BY `id` ASC", array($thread), true); //place holders $i = 0; //the position of post $x = 0; //0 = not found : 1 = found while($x == 0) { if($thread[$i]['id'] == $post) $x = 1; $i++; } return ceil($i/$per_page); } else { return false; } } /* * @METHOD formatPost * @DESC converts text to smileys, adds forum quotes, filters/cleans post, add signatures */ public function formatPost($content, $username, base $base, user $user, forum $forum = null) { //config $config = $base->loadConfig(); //get the rank of the user $rank = $user->getRank($username); $donator = $user->isDonator($username); //username of viewer $viewer = $user->getUsername($_COOKIE['user'], 2); //users & fmods if($rank < 2) { //apply filter for USERS if the forum variable is set if(!is_null($forum) && $rank < 3) $forum->filter($content); //remove HTML $content = htmlentities($content); } //youtube bbcode is seperate from other bbcodes, because only the youtube bbcodes can be toggled on/off for members if($rank > 1 || $config['bbcode_members']) $content = preg_replace('#\[youtube\](.+?)\[\/youtube\]#', '<iframe width="560" height="315" src="http://www.youtube.com/embed/$1?rel=0" frameborder="0" allowfullscreen></iframe>', $content); //show content within [donator] tags only to donators $content = preg_replace('#\[donator\](.+?)\[\/donator\]#is', ($user->isDonator($viewer) || $user->getRank($viewer) > 1) ? '<div class="donor_only"><center><font color="00FFFF">Donator Only</font></center><br/>$1</div>' : '<i>This content can only be seen by donators.</i>', $content); $content = preg_replace(array('#@(\d{1,1}-\d{1,1}-\d{4,4}-\d{5,5})#i', '#:iloveyou:#i', '#:pumpkin:#i'), array('<a href="jump.php?qfc=$1">$1</a>', '<img src="../img/forum/smileys/heart.png" width="15" height="15">', '<img src="../img/forum/smileys/pumpkin.png" width="15" height="15">'), $content); //now let's do BBCode for mods and admins if($rank > 2 || $donator) { //bcode and some smileys $bbcode = array('#\[b\](.+?)\[\/b\]#i', '#\[i\](.+?)\[\/i\]#i', '#\[url=(.+?)](.+?)\[\/url\]#i', '#\[u\](.+?)\[\/u\]#i', '#:lolbert:#i', '#\[img\](.+?)\[\/img\]#i', '#:donator:#i', '#:cheken:#i'); $replace = array('<b>$1</b>', '<i>$1</i>', '<a href="$1">$2</a>', '<u>$1</u>', '<img src="../img/forum/smileys/lolbert.png">', '<img src="$1" border="0">', '<img src="../img/forum/smileys/blue_partyhat.gif" width="15" height="15">', '<img src="../img/forum/smileys/cheken.png" width="15" height="15">'); $content = preg_replace($bbcode, $replace, $content); if($rank == 4) { //convert QUOTE BBcode to actual HTML format $content = stripslashes(preg_replace('/\[quote\=(.+?)](.+?)\[\/quote\]/s', '<blockquote> <h5><strong>Original Post</strong> - Posted by: <strong>$1</strong></h5> <p><i>$2</i></p> </blockquote> ', $content)); } } //add smileys if($user->smileyC()){ $text = array(':)', ';)', ':P', ':(', ':|', 'O_o', ':D', '^^', ':O', ':@'); $smileys = array('<img src="../img/forum/smileys/smile.gif">', '<img src="../img/forum/smileys/wink.gif">', '<img src="../img/forum/smileys/tongue.gif">', '<img src="../img/forum/smileys/sad.gif">', '<img src="../img/forum/smileys/nosmile.gif">', '<img src="../img/forum/smileys/o.O.gif">', '<img src="../img/forum/smileys/bigsmile.gif">', '<img src="../img/forum/smileys/^^.gif">', '<img src="../img/forum/smileys/shocked.gif">', '<img src="../img/forum/smileys/angry.gif">'); } $signature = $user->getSignature($username); if($rank > 3){ $content = $content.((strlen($signature) > 0) ? '<br/><br/>'.$user->getSignature($username) : ''); } return $content = stripslashes(str_replace($text, $smileys, $content)); } public function getActionBar($rank, $id, $forum) { //check if the post is already reported $this->database->processQuery("SELECT * FROM `reports` WHERE `reported` = ?", array($id.':t'), true); $report = ($this->database->getRowCount() >= 1) ? '<span style="color:#C0C0C0">Report</span>' : '<a href="report.php?forum='. $forum .'&id='. $id. '&type=2">Report</a>'; //set the base url $base_url = '?forum='. $forum .'&id='. $id; //display their action bar switch($rank) { case 1: case 2: $bar = $report; break; case 3: $bar = '<a href="edit.php'. $base_url .'&type=2">Edit</a>'; break; case 4: $bar = '<div class="button invert"><a href="reply.php'. $base_url .'"e='. $id .'&qt=2">Quote</a> | <a href="edit.php'. $base_url .'&type=2">Edit</a></div>'; break; } return $bar; } public function bumpThread($id, $username) { $thread = $this->database->processQuery("SELECT `username` FROM `threads` WHERE `id` = ? LIMIT 1", array($id), true); if($thread[0]['username'] == $username) $this->database->processQuery("UPDATE `threads` SET `lastbump` = ? WHERE `id` = ?", array(time(), $id), false); } } ?>
If anybody is to help me I will be very very greatful for any advice and help to reassure the issue.
If you'd like to see the horrible mess I've been left with, then please message me .
PS:
I know the website probably has other bugs but this is coming to me as a "Major NEED" to sort out as soon as I can, I paid for a custom forum for my website to be created on, however that's gone pair-shaped.
Trying to build a simple router. Still needs work, but one place I am stuck on is where I define my endpoints in index.php. Specifically, how do I access $router when within the callback? I see that my use of $this is incorrect as I am not in object context. What do I need to change to make it in object context? Thanks
$router->get('pattern', function(Request $request){ //How do I access $this? });
index.php
<?php error_reporting(E_ALL); ini_set('display_startup_errors', 1); ini_set('display_errors', 1); spl_autoload_register(function ($classname) { $parts = explode('\\', $classname); require __DIR__."/../src/".end($parts).".php"; }); $c = new Pimple(); $c['view'] = function ($c) { return new View(); }; $router = new Router($c); $router->get('/^\/test\/?$/', function(Request $request, Response $response){ var_dump($request); var_dump($response); }); $router->get('/^\/test\/(\w+)\/?$/', function(Request $request, Response $response){ var_dump($request); var_dump($response); }); $router->get('/^\/test\/(\w+)\/(\d+)\/?$/', function(Request $request, Response $response){ var_dump($request); var_dump($response); }); $router->get('/^\/index.php\/?$/', function(Request $request){ var_dump($this);var_dump($request); var_dump($response); }); $router->run();
<?php class Router { private $routes = []; private $container = []; public function __construct($container) { $this->container=$container; } public function get($pattern, $callback) { $this->routes['GET'][$pattern] = $callback; } public function post($pattern, $callback) { $this->routes['POST'][$pattern] = $callback; } public function put($pattern, $callback) { $this->routes['PUT'][$pattern] = $callback; } public function delete($pattern, $callback) { $this->routes['DELETE'][$pattern] = $callback; } public function run() { $uri=$_SERVER['REQUEST_URI']; foreach ($this->routes[$_SERVER['REQUEST_METHOD']] as $pattern => $callback) { if (preg_match($pattern, $uri, $params) === 1) { return call_user_func($callback, new Request($params)); } } } }
<?php class Request { private $params = []; private $uri; public function __construct(array $params) { $this->uri=$params[0]; array_shift($params); $this->params=array_values($params); } public function getUri() { return $this->uri; } public function getParams() { return $this->params; } public function getData() { switch($_SERVER['REQUEST_METHOD']){ case 'GET':$data=$_GET;break; case 'POST':$data=$_POST;break; case 'PUT': parse_str(file_get_contents("php://input"),$data); /* //Or do it per http://php.net/manual/en/features.file-upload.put-method.php? $putdata = fopen("php://input", "r"); // Read the data 1 KB at a time and write to a stream while ($data = fread($putdata, 1024)) { fwrite($fp, $data); } fclose($fp); */ break; case 'DELETE': //Can a delete method have data? Is it the same as $_GET? $data=$_GET; break; } return $data; } }
I cannot continue my PHP work because an error (Registration form).Parse error: syntax error, unexpected end of file in ....... on line 7
My PHP code is:
<?php
Hello everyone,
I have a database of information and links to images(photos) on my servers filesystem. I'd like to write a script that reads from the database and updates my webpage automatically. In my database I have a timestamp along with a title, description and a link to a relevant image(photo). I'd like to somehow read from the database and only show records that are past a given time. My database is mySQL and the timestamp in the database is stored as a mySQL datetime datatype.
1. How to I convert the mySQL datetime to a php date so that I can compare the current php time with the mySQL datetime and then make a decision to post records only those records that are before the current time plus a random time between 5 and 15 minutes.
Although I've been programming with php for awhile, I still can't quite wrap my mind around how the php code or sql query would look to perform this task.
My goal is to read from the database and post only those records that have a datetime that is anywhere from 5 to 15 minutes later than php's current time on the server.
I actually have a php form that I use to update the database with new records(title,description,image(photo) link). My goal is to have the website auto update itself based on the records that I have scheduled to be posted based on 5 to 15 minutes from my php current time.
I usually write object oriented php, any help on some idea's about how this should/could be done would be appreciated.
please and thanks,
FalsAlarm,
Hi good guy!
i'm facing some problems setting up pre-made website! i really need it for buisness use so far.
the problem is i don't have that much of knewledge of php and mysql ect ! i'm using 000webhost and when i put the files together and link the website to mysql i always gets errors at login page when i'm sure there's just a very tiny problem can be fixed by you very quiq ! anyone can help me please ? just 10min of your time and i'll appericiate it!
anyways here's the problem i gets on login..
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /storage/ssd1/425/3721425/public_html/login.php on line 22
i just attached the login and config files ! if you can just fix it by taking a look at these files let me know! if no please tell me that we can message each others.
BIIIIIIIIIIIIG THANKS
I need to bring from database the alt tag description, column name is alt_tag and put in the following section alt="description to go here"
Thanking anyone that can help me.
p.s it may be simple to you guys but I am new to all this
Code:
<div class="large_col floatL">
<div class="featured">
<div class="slider">
<?php $i=1;if(count($banner)>0) { foreach($banner as $rows) { ?>
<div class="slide" <?php if($i>1) echo 'style="display:none"';?>><a href="<?=$rows->ban_url?>"><img src="<?=base_url()?>banner_images/<?=$rows->ban_image?>" alt="" width="670" height="149" /></a></div>
<?php $i++;} } ?>
</div>
Trying to build a simple router. Still needs work, but one place I am stuck on is where I define my endpoints in index.php. Specifically, how do I access $router when within the callback? I see that my use of $this is incorrect as I am not in object context. What do I need to change to make it in object context? Thanks
$router->get('pattern', function(Request $request){ //How do I access $this? });
index.php
<?php error_reporting(E_ALL); ini_set('display_startup_errors', 1); ini_set('display_errors', 1); spl_autoload_register(function ($classname) { $parts = explode('\\', $classname); require __DIR__."/../src/".end($parts).".php"; }); $c = new Pimple(); $c['view'] = function ($c) { return new View(); }; $router = new Router($c); $router->get('/^\/test\/?$/', function(Request $request, Response $response){ var_dump($request); var_dump($response); }); $router->get('/^\/test\/(\w+)\/?$/', function(Request $request, Response $response){ var_dump($request); var_dump($response); }); $router->get('/^\/test\/(\w+)\/(\d+)\/?$/', function(Request $request, Response $response){ var_dump($request); var_dump($response); }); $router->get('/^\/index.php\/?$/', function(Request $request){ var_dump($this);var_dump($request); var_dump($response); }); $router->run();
<?php class Router { private $routes = []; private $container = []; public function __construct($container) { $this->container=$container; } public function get($pattern, $callback) { $this->routes['GET'][$pattern] = $callback; } public function post($pattern, $callback) { $this->routes['POST'][$pattern] = $callback; } public function put($pattern, $callback) { $this->routes['PUT'][$pattern] = $callback; } public function delete($pattern, $callback) { $this->routes['DELETE'][$pattern] = $callback; } public function run() { $uri=$_SERVER['REQUEST_URI']; foreach ($this->routes[$_SERVER['REQUEST_METHOD']] as $pattern => $callback) { if (preg_match($pattern, $uri, $params) === 1) { return call_user_func($callback, new Request($params)); } } } }
<?php class Request { private $params = []; private $uri; public function __construct(array $params) { $this->uri=$params[0]; array_shift($params); $this->params=array_values($params); } public function getUri() { return $this->uri; } public function getParams() { return $this->params; } public function getData() { switch($_SERVER['REQUEST_METHOD']){ case 'GET':$data=$_GET;break; case 'POST':$data=$_POST;break; case 'PUT': parse_str(file_get_contents("php://input"),$data); /* //Or do it per http://php.net/manual/en/features.file-upload.put-method.php? $putdata = fopen("php://input", "r"); // Read the data 1 KB at a time and write to a stream while ($data = fread($putdata, 1024)) { fwrite($fp, $data); } fclose($fp); */ break; case 'DELETE': //Can a delete method have data? Is it the same as $_GET? $data=$_GET; break; } return $data; } }
I have an app that uploads screenshots and I have a webpage that users can go to to view/save the images.
The webpage just has a form to select a month/day/hour from dropdowns on a form, then updates the page with ajax and displays images echo'd out by the php as it iterates over that month/day/hour's directory, populating an image tag with the url of the image, in an echo statement.
echo '<img src="' . 'https://mydomain.com/client/uploads/' . $_GET["month"] . '/' . $_GET["day"] . '/' . $_GET["hour"] . '/' . $fileInfo->getFilename() .'"/>';
It properly displays all the images and works for the public facing site. I then made a non public page that does the same thing and am trying to make the delete button like:
echo '<button onclick="function Delete() { console.log(5);}">Delete</button><br />'; //test echo '<button onclick="Delete();">Delete</button><br />'; //test echo '<img src="' . 'https://mydomain.com/client/uploads/' . $_GET["month"] . '/' . $_GET["day"] . '/' . $_GET["hour"] . '/' . $fileInfo->getFilename() .'"/>';
The delete buttons do nothing. On my html page I have in the head tags but it never gets called.
<script> function Delete() { console.log("Delete"); }</script>
I'm trying to just get the basic communication with the javascript function so I can then change it to POST/GET that image's path to my deleteFile.php script to delete that specific image. Doesn't even need to update the page it's just a very very very basic moderation functionality not publicly showing so someone can scroll through the images and delete them off my server.
Any ideas why the javascript function doesn't get called? And how I can fix it?
Hi
I wrote this code in notepad ++ :
<?php ini_set("memory_limit",-1); $myArray = Array(); $connection = mysqli_connect("localhost","my_user","my_password","my_db"); $result = mysqli_query($connection, "SELECT * FROM tablename"); while(($row = mysqli_num_rows($result))== null){ array_push($myArray,$row); } echo json_encode($myArray); mysqli_close($connection ); ?>
And run it with wamp localhost . Then I got this error in my browser :
Fatal error: Out of memory (allocated 408944640) (tried to allocate 805306376 bytes) in D:\...\page1.php on line 10
What's problem ? Can anybody says ?
I am working with an api that gives this response in this format each time it is called:
> OK|*random sequence of numbers*|http://response.com/0/123456
How can i automatically redirect people to response.com url?
Below is the current PHP script i am using
<?php
$url = 'http://example.com/api/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = curl_exec($ch);
Hi,
I am quite new to programming and would need some help please. Getting crazy here
I have a PHP Proxy Script and I try to get it to work. Here is the link to it:
https://gist.github.com/m-thomson/c872e7da848ceba055ad036791daa32d
I want to get as an outcome a .csv file what I then can use from an https site instead of ftp.
Because my Wordpress plugin is not supporting ftp.
I put all the information in and I get a download file but the file is empty. There should be all the Product data ect. in there.
Can anybody help? Is there anything I miss out? As I understand the script I only need to put in the password, username and ftp link and after I should get the file. Am I right?
Thank you
Regards
hulkmaster